Skip to content

Instantly share code, notes, and snippets.

@Bobris
Created June 13, 2011 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bobris/1023790 to your computer and use it in GitHub Desktop.
Save Bobris/1023790 to your computer and use it in GitHub Desktop.
Benchmark for BTDB
void DoWork5(bool alsoDoReads)
{
_sw.Restart();
long pureDataLength = 0;
using (var stream = new PositionLessStreamProxy("data.btdb"))
using (IKeyValueDB db = new KeyValueDB())
{
db.DurableTransactions = true;
db.CacheSizeInMB = 40;
db.Open(stream, false);
for (int i = 0; i < 200; i++)
{
long pureDataLengthPrevTr = pureDataLength;
using (var tr = db.StartTransaction())
{
for (int j = 0; j < 200; j++)
{
tr.CreateOrUpdateKeyValue(new[] { (byte)j, (byte)i }, new byte[1 + i * j]);
pureDataLength += 2 + 1 + i * j;
}
if (alsoDoReads) using (var trCheck = db.StartTransaction())
{
long pureDataLengthCheck = 0;
if (trCheck.FindFirstKey())
{
do
{
pureDataLengthCheck += trCheck.ReadKey().Length + trCheck.ReadValue().Length;
} while (trCheck.FindNextKey());
}
if (pureDataLengthCheck != pureDataLengthPrevTr)
{
throw new Exception("Transactions are not in serializable mode");
}
}
tr.Commit();
}
}
using (var trStat = db.StartTransaction())
{
Console.WriteLine(trStat.CalculateStats().ToString());
}
}
_sw.Stop();
Console.WriteLine("Pure data length: {0}", pureDataLength);
Console.WriteLine("Time: {0,15}ms", _sw.Elapsed.TotalMilliseconds);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment