Skip to content

Instantly share code, notes, and snippets.

@mattwarren
Created October 8, 2011 21:13
Show Gist options
  • Save mattwarren/1272883 to your computer and use it in GitHub Desktop.
Save mattwarren/1272883 to your computer and use it in GitHub Desktop.
Json Bson Benchmarks for RavenDB
var numItems = 100000;
var dictionary = new Dictionary<string, Foo>(numItems);
for (int i = 0; i < numItems; i++)
{
var foo = new Foo { Id = "foo/" + i.ToString(), Counter = i + 1, Data = "Some Data " + i.ToString() };
dictionary.Add(foo.Id, foo);
}
var timer = Stopwatch.StartNew();
var jsonObj = RavenJObject.FromObject(dictionary);
timer.Stop();
Console.WriteLine("Serialization took {0:0.00} msecs", timer.ElapsedMilliseconds);
var rawJson = jsonObj.ToString();
var rawBson = jsonObj.ToBytes();
var parseTimer = Stopwatch.StartNew();
var newJsonOb = RavenJObject.Parse(rawJson);
parseTimer.Stop();
var deserializeTimer = Stopwatch.StartNew();
var newDictionary = newJsonOb.JsonDeserialization<Dictionary<string, Foo>>();
deserializeTimer.Stop();
Console.WriteLine("DE-serialization took {0:0.00} msecs, parsing took {1:0.00} msecs",
deserializeTimer.ElapsedMilliseconds, parseTimer.ElapsedMilliseconds);
Console.WriteLine(" Total time was {0:0.00} msecs",
deserializeTimer.ElapsedMilliseconds + parseTimer.ElapsedMilliseconds);
var bsonParseTimer = Stopwatch.StartNew();
var newFromBsonJsonOb = rawBson.JsonDeserialization<Dictionary<string, Foo>>();
parseTimer.Stop();
Console.WriteLine("DE-serialization from BSON took {0:0.00} msecs", bsonParseTimer.ElapsedMilliseconds);
public class Foo
{
public string Id { get; set; }
public string Data { get; set; }
public List<decimal> List { get; set; }
public int Counter { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment