Created
March 16, 2010 22:42
-
-
Save gamlerhart/334634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.IO; | |
using Db4objects.Db4o; | |
using Db4objects.Db4o.Config; | |
namespace Gamlor.Db4oForum | |
{ | |
class RunBenchmark | |
{ | |
public static void Main(string[] args) | |
{ | |
File.Delete("testMe.db4o"); | |
using (var db = Db4oEmbedded.OpenFile(NewConfig(), "testMe.db4o")) | |
{ | |
for (var i = 0; i < 1000000; i++) | |
{ | |
var tl = new GroundTile(new TileID(i % 333000, i % 333000), i * 22, string.Format("Texture {0}", i)); | |
db.Store(tl); | |
} | |
} | |
using (var db = Db4oEmbedded.OpenFile(NewConfig(), "testMe.db4o")) | |
{ | |
{ | |
var ts = Stopwatch.StartNew(); | |
IList<GroundTile> results = db.Query(delegate(GroundTile groundTile) | |
{ | |
return groundTile.TileID.X == 10 && groundTile.TileID.Y == 10; | |
}); | |
foreach (GroundTile groundTile in results) | |
{ | |
Console.WriteLine(groundTile); | |
} | |
Console.Out.WriteLine(ts.ElapsedMilliseconds); | |
} | |
{ | |
var ts = Stopwatch.StartNew(); | |
IList<GroundTile> results = db.Query(delegate(GroundTile groundTile) | |
{ | |
return groundTile.TileID.X == 42421 && groundTile.TileID.Y == 42421; | |
}); | |
foreach (GroundTile groundTile in results) | |
{ | |
Console.WriteLine(groundTile); | |
} | |
Console.Out.WriteLine(ts.ElapsedMilliseconds); | |
} | |
{ | |
var ts = Stopwatch.StartNew(); | |
IList<GroundTile> results = db.Query(delegate(GroundTile groundTile) | |
{ | |
return groundTile.TileID.X == 2421 && groundTile.TileID.Y == 2421; | |
}); | |
foreach (GroundTile groundTile in results) | |
{ | |
Console.WriteLine(groundTile); | |
} | |
Console.Out.WriteLine(ts.ElapsedMilliseconds); | |
} | |
} | |
Console.Out.WriteLine("DOne"); | |
Console.Read(); | |
} | |
private static IEmbeddedConfiguration NewConfig() | |
{ | |
var cfg = Db4oEmbedded.NewConfiguration(); | |
cfg.Common.ObjectClass(typeof(GroundTile)).ObjectField("tileID").Indexed(true); | |
cfg.Common.ObjectClass(typeof(TileID)).ObjectField("x").Indexed(true); | |
cfg.Common.ObjectClass(typeof(TileID)).ObjectField("y").Indexed(true); | |
return cfg; | |
} | |
} | |
class GroundTile | |
{ | |
public GroundTile(TileID tileID, int heigh, string textureID) | |
{ | |
this.tileID = tileID; | |
this.heigh = heigh; | |
this.textureID = textureID; | |
} | |
private TileID tileID; | |
internal TileID TileID | |
{ | |
get { return tileID; } | |
set { tileID = value; } | |
} | |
private int heigh; | |
public int Heigh | |
{ | |
get { return heigh; } | |
set { heigh = value; } | |
} | |
private string textureID; | |
public string TextureID | |
{ | |
get { return textureID; } | |
set { textureID = value; } | |
} | |
public override string ToString() | |
{ | |
return string.Format("TileID: x = {0}, y = {1}", tileID.X, tileID.Y); | |
} | |
} | |
class TileID | |
{ | |
public TileID(int x, int y) | |
{ | |
this.x = x; | |
this.y = y; | |
} | |
private int x; | |
public int X | |
{ | |
get { return x; } | |
set { x = value; } | |
} | |
private int y; | |
public int Y | |
{ | |
get { return y; } | |
set { y = value; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment