private Task<BenchmarkResult> SeekRandom(BenchmarkParameters parameters) { var random = new Random(); var found = 0; var result = new BenchmarkResult(parameters); for (var i = 0; i < parameters.Reads; i++) { using (var iterator = storage.Reader.NewIterator(new ReadOptions())) { var k = random.Next() % options.Num; var key = string.Format("{0:0000000000000000}", k); Slice sliceKey = key; iterator.Seek(sliceKey); if (iterator.IsValid && sliceKey.CompareTo(iterator.Key) == 0) found++; result.FinishOperation(); } } result.AddMessage(string.Format("({0} of {1} found)", found, parameters.Num)); return Task.FromResult(result); }
private Task<BenchmarkResult> ReadRandom(BenchmarkParameters parameters) { var random = new Random(); var found = 0; var result = new BenchmarkResult(parameters); for (int i = 0; i < parameters.Reads; i++) { var k = random.Next() % options.Num; var key = string.Format("{0:0000000000000000}", k); using (var streamValue = storage.Reader.Read(key)) { if (streamValue != null) found++; } result.FinishOperation(); } result.AddMessage(string.Format("({0} of {1} found)", found, parameters.Num)); return Task.FromResult(result); }
private Task<BenchmarkResult> Crc32c(BenchmarkParameters parameters) { const long Size = 4096; var buffer = new byte[Size]; for (int i = 0; i < Size; i++) { buffer[i] = (byte)'x'; } var result = new BenchmarkResult(parameters); long bytes = 0; uint crc = 0; while (bytes < 500 * 1048576) { crc = Crc.Value(buffer, 0, buffer.Length); bytes += Size; result.FinishOperation(); } result.AddBytes(bytes); result.AddMessage("(4K per op)"); result.AddMessage(string.Format("CRC is {0}", crc)); return new CompletedTask<BenchmarkResult>(result); }