|
using System;
using System.Diagnostics;
using System.Collections;
using System.IO;
using System.Text;
using System.Threading;
using RaptorDB;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace testing
{
public class bplusTest
{
public static void StringKeyTest()
{
var db = RaptorDB<string>.Open("c:\\raptordbtest\\strings", 255, true);
for (int i = 0; i < 100000; i++)
{
db.Set("asdfasd" + i, "" + i);
}
db.Shutdown();
}
private static void test()
{
int count = 10 * 1000000;
string dbpath = "c:\\RaptorDbTest\\test1";
var rap = RaptorDB<Guid>.Open(dbpath, true);
Console.WriteLine("---------------");
Console.WriteLine("Writing " + count.ToString("#,#"));
List<Guid> guid = new List<Guid>();
for (int i = 0; i < count; i++)
guid.Add(Guid.NewGuid());
DateTime dt = DateTime.Now;
for (int i = 0; i < count; i++)
{
rap.Set(guid[i], "" + guid[i]);
if (i % 100000 == 0)
Console.Write(".");
}
Console.WriteLine("set done");
double st = DateTime.Now.Subtract(dt).TotalSeconds;
//rap.Shutdown();
//rap = RaptorDB<Guid>.Open(dbpath, true);
dt = DateTime.Now;
int failed = 0;
for (int i = 0; i < count; i++)
{
if (i % 100000 == 0)
Console.Write(".");
string str = "";
if (rap.Get(guid[i], out str) == false)
failed++;
else
{
if (str != "" + guid[i])
failed++;
}
}
Console.WriteLine("get done");
if (failed > 0)
Console.WriteLine("failed count = " + failed);
//Console.WriteLine(rap.GetStatistics());
Console.WriteLine("set time = " + st);
Console.WriteLine("get time = " + DateTime.Now.Subtract(dt).TotalSeconds);
rap.Shutdown();
}
private static void testnoget()
{
int count = 100 * 1000000;
string dbpath = "c:\\RaptorDbTest\\test1";
var rap = RaptorDB<Guid>.Open(dbpath, true);
Console.WriteLine("---------------");
Console.WriteLine("Writing " + count.ToString("#,#"));
//List<Guid> guid = new List<Guid>();
//for (int i = 0; i < count; i++)
// guid.Add(Guid.NewGuid());
DateTime dt = DateTime.Now;
for (int i = 0; i < count; i++)
{
Guid g = Guid.NewGuid();
rap.Set(g, "" + g);
if (i % 100000 == 0)
Console.Write(".");
}
Console.WriteLine("set done");
double st = DateTime.Now.Subtract(dt).TotalSeconds;
//rap.Shutdown();
//rap = RaptorDB<Guid>.Open(dbpath, true);
//dt = DateTime.Now;
//int failed = 0;
//for (int i = 0; i < count; i++)
//{
// if (i % 100000 == 0)
// Console.Write(".");
// string str = "";
// if (rap.Get(guid[i], out str) == false)
// failed++;
// else
// {
// if (str != "" + guid[i])
// failed++;
// }
//}
//Console.WriteLine("get done");
//if (failed > 0)
// Console.WriteLine("failed count = " + failed);
//Console.WriteLine(rap.GetStatistics());
Console.WriteLine("set time = " + st);
//Console.WriteLine("get time = " + DateTime.Now.Subtract(dt).TotalSeconds);
rap.Shutdown();
Console.ReadKey();
}
public static void RunPageCount(ushort count)
{
Console.WriteLine("page item count = " + count);
RaptorDB.Global.PageItemCount = count;
Directory.Delete("c:\\RaptorDbTest\\", true);
test();
}
public static void InsertItemsRaptorDB()
{
//string guid = Guid.NewGuid().ToString();
string dbPath = "test\\test";
var database = RaptorDB.RaptorDB<Int32>.Open(dbPath, false);
int start = 0;// 50000000;
Int32 insertedItems = 0;
for (Int32 i = start; i < Int32.MaxValue; i++)
{
if (insertedItems == 10000000)
{
Console.WriteLine("finished " + i.ToString("#,0"));
// Flush index
database.Dispose();
database = RaptorDB.RaptorDB<Int32>.Open(dbPath, false);
insertedItems = 0;
}
insertedItems++;
database.Set(i, new byte[] { (byte)(i & 0xFF) });
}
database.Dispose();
}
public static void Main()
{
InsertItemsRaptorDB();
//test();
//testnoget();
//RunPageCount(30000);
//RunPageCount(20000);
//RunPageCount(10000);
//RunPageCount(5000);
//RunPageCount(1000);
Console.ReadKey();
return;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Mehdi first started programming when he was 8 on BBC+128k machine in 6512 processor language, after various hardware and software changes he eventually came across .net and c# which he has been using since v1.0.
He is formally educated as a system analyst Industrial engineer, but his programming passion continues.
* Mehdi is the 5th person to get 6 out of 7 Platinum's on Code-Project (13th Jan'12)
* Mehdi is the 3rd person to get 7 out of 7 Platinum's on Code-Project (26th Aug'16)