static void LiteId(string[] args) { if (args.Length < 1) { Console.WriteLine("LiteDb complex id insertion benchmark. Supply number of items to insert"); Console.WriteLine("Example: benchmark.exe liteId 10000"); return; } var count = int.Parse(args[0]); var longId = 1L; var intId = 1; DoBenchmark("Base", () => new LiteEntityInt { Id = intId++, Address = "some address long", Amount = 123, PersonName = "some person name" }); DoBenchmark("Base", () => new LiteEntityLong { Id = longId++, Address = "some address long", Amount = 123, PersonName = "some person name" }); DoBenchmark("SequentialGuid", () => new LiteEntityId { Id = new Id <LiteEntityId>(SequentialGuid.SequentialGuidGenerator.Instance.NewGuid()), Address = "some address long", Amount = 123, PersonName = "some person name" }); BsonMapper.Global.RegisterType(x => x.ToString(), x => Ulid.Parse(x)); DoBenchmark("String Ulid", () => new LiteEntityLid { Id = Lid <LiteEntityLid> .NewId(), Address = "some address long", Amount = 123, PersonName = "some person name" }); BsonMapper.Global.RegisterIdBsonMappers(typeof(Program).Assembly); DoBenchmark("String SGuid", () => new LiteEntityId { Id = new Id <LiteEntityId>(SequentialGuid.SequentialGuidGenerator.Instance.NewGuid()), Address = "some address long", Amount = 123, PersonName = "some person name" }); void DoBenchmark <T>(string name, Func <T> faker) where T : class { var storageFile = name + faker.GetType().GenericTypeArguments[0].Name + ".litedb"; if (File.Exists(storageFile)) { File.Delete(storageFile); } using var repo = LiteRepo.WithUtcDate(storageFile); var sw = Stopwatch.StartNew(); for (int i = 0; i < 100; i++) { repo.Insert(faker()); } sw.Restart(); for (int i = 0; i < count; i++) { repo.Insert(faker()); } sw.Stop(); Console.WriteLine($"{name,-20} {typeof(T).Name,-20}: {sw.ElapsedMilliseconds,6} ms, {count * 1000 / sw.ElapsedMilliseconds,5} iops"); } }
public bool Equals(Lid <T> other) { return(Value.Equals(other.Value)); }