private static int DoBenchmark(BenchmarkOptions opts) { var N = opts.Count; var skip = 1000UL; foreach (var name in PostingListIOFactory.GetNames()) { DoBenchmarkPostingList(name, N, skip); } return(1); }
private static void DoBenchmarkPostingList(string name, ulong count, ulong skip) { using (var ms = new Core.Common.Persistance.MemoryStorage()) { var address = default(PostingListAddress); var timer = Stopwatch.StartNew(); using (var writer = PostingListIOFactory.CreateWriter(name, ms.GetReference())) { writer.StartList(string.Empty); for (ulong i = 0; i < count; ++i) { writer.AddOccurrence(Occurrence.O(1, 1, skip + i)); } address = writer.EndList(); } PrintConsole(ConsoleColor.Magenta, $"Encoder {name}"); PrintConsole(ConsoleColor.Magenta, $"\tCount : {count}"); PrintConsole(ConsoleColor.Magenta, $"\tSize : {ms.Length}"); PrintConsole(ConsoleColor.Magenta, $"\tWrite : {timer.Elapsed}"); timer = Stopwatch.StartNew(); using (var reader = PostingListIOFactory.CreateReader(name, ms.GetReference())) { // Linear Scan { ulong i = 0; foreach (var actual in reader.Get(address)) { var target = Occurrence.O(1, 1, skip + i); if (target != actual) { throw new Exception(); } ++i; } } var list = reader.Get(address).AsSkipList(); for (ulong i = 0; i < count; ++i) { var target = Occurrence.O(1, 1, skip + i); var actual = list.LowerBound(target).FirstOrDefault(); if (target != actual) { throw new Exception(); } } for (ulong i = 1; i < skip; ++i) { var target = Occurrence.O(1, 1, i); var actual = list.LowerBound(target).FirstOrDefault(); if (actual != Occurrence.O(1, 1, skip)) { throw new Exception(); } } for (ulong i = count + 1; i < count + skip; ++i) { var target = Occurrence.O(1, 1, skip + i); var actual = list.LowerBound(target).FirstOrDefault(); if (actual != Occurrence.Empty) { throw new Exception(); } } } PrintConsole(ConsoleColor.Magenta, $"\tSeek : {timer.Elapsed}"); } }