Skip to content

Instantly share code, notes, and snippets.

@BillKeenan
Created September 21, 2012 15:48
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 BillKeenan/3762270 to your computer and use it in GitHub Desktop.
Save BillKeenan/3762270 to your computer and use it in GitHub Desktop.
using System.Runtime.Serialization;
using Couchbase;
using Enyim.Caching.Memcached;
using Raven.Abstractions.Data;
using Raven.Client.Document;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace COuchvsRaven
{
internal class Program
{
private static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
var count = 100000;
Console.WriteLine("Starting Couch Test");
TestCouch(count);
Console.WriteLine("Starting Ravend Test");
TestRaven(count);
}
public static void TestCouch(int count)
{
using (var couchbaseClient = new CouchbaseClient())
{
for (int i = 1; i < count; i++)
{
couchbaseClient.Remove("test:" + i);
}
}
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
TestCouchWrite(count);
sw.Stop();
Console.WriteLine("{2} :{0} milleseconds for {1} items writer",sw.ElapsedMilliseconds,count,sw.ElapsedMilliseconds/count);
Console.WriteLine("starting read test");
sw.Restart();
TestCouchRead(count);
sw.Stop();
Console.WriteLine("{2} :{0} milleseconds for {1} items reade", sw.ElapsedMilliseconds, count, sw.ElapsedMilliseconds / count);
Console.ReadLine();
}
public static void TestRaven(int count)
{
using (var doc = new DocumentStore { ConnectionStringName = "Raven" }.Initialize())
{
using (var sess = doc.OpenSession("Test"))
{
sess.Advanced.DatabaseCommands.DeleteByIndex("Raven/DocumentsByEntityName",
new IndexQuery {}, false);
}
}
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
TestRavenWrite(count);
sw.Stop();
Console.WriteLine("{2} :{0} milleseconds for {1} items writer",sw.ElapsedMilliseconds,count,sw.ElapsedMilliseconds/count);
Console.WriteLine("starting read test");
sw.Restart();
TestRavenWrite(100000);
sw.Stop();
Console.WriteLine("{2} :{0} milleseconds for {1} items reade", sw.ElapsedMilliseconds, count, sw.ElapsedMilliseconds / count);
Console.ReadLine();
}
public static void TestRavenWrite(int count)
{
using (var doc = new DocumentStore { ConnectionStringName = "Raven" }.Initialize())
{
var obs = new List<TestObject>();
for (int i = 1; i < count; i++)
{
obs.Add(MakeObject(i));
if (i % 20 == 0)
{
using (var sess = doc.OpenSession("Test"))
{
foreach (var ob in obs)
{
sess.Store(ob);
}
sess.SaveChanges();
obs.Clear();
}
}
}
}
}
public static void TestCouchWrite(int count)
{
using (var couchbaseClient = new CouchbaseClient())
{
for (int i = 1; i < count; i++)
{
var result = couchbaseClient.Store(StoreMode.Add, "test:" + i, MakeObject(i));
if (!result)
{
throw new Exception("argh");
}
}
}
}
public static void TestCouchRead(int count)
{
using (var couchbaseClient = new CouchbaseClient())
{
for (int i = 1; i < count; i++)
{
var ob = couchbaseClient.Get<TestObject>("test:"+i);
if (ob == null)
{
throw new ArgumentException("argh");
}
}
}
}
public static void TestRavenRead(int count)
{
using (var doc = new DocumentStore { ConnectionStringName = "Raven" }.Initialize())
using (var sess = doc.OpenSession("Test"))
{
for (int i = 1; i < count; i++)
{
var ob = sess.Load<TestObject>(i);
if (ob == null)
{
throw new ArgumentException("argh");
}
}
}
}
public static TestObject MakeObject(int i)
{
var rnd = new Random();
var tst = new TestObject
{
Id=i,
one = "hi"+i,
two = "therse",
TestObjects = MakeSubs(rnd.Next(0,80))
};
return
tst;
}
public static List<SubObject> MakeSubs(int count)
{
var ret = new List<SubObject>();
for (int i = 0; i < count; i++)
{
ret.Add(new SubObject {one = "monkeys"});
}
return ret;
}
[Serializable]
public class TestObject
{
public TestObject()
{
TestObjects = new List<SubObject>();
}
[DataMember]
public string one { get; set; }
[DataMember]
public string two { get; set; }
[DataMember]
public List<SubObject> TestObjects { get; set; }
[DataMember]
public int Id { get; set; }
}
[Serializable]
public class SubObject
{
[DataMember]
public string one { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment