private Task<BenchmarkResult> ReadSequential(BenchmarkParameters parameters) { var result = new BenchmarkResult(parameters); using (var iterator = storage.Reader.NewIterator(new ReadOptions())) { var i = 0; long bytes = 0; for (iterator.SeekToFirst(); i < parameters.Reads && iterator.IsValid; iterator.Next()) { using (var valueStream = iterator.CreateValueStream()) { bytes += iterator.Key.Count + valueStream.Length; } result.FinishOperation(); ++i; } result.AddBytes(bytes); return Task.FromResult(result); } }
private Task<BenchmarkResult> DoWrite(BenchmarkParameters parameters, bool seq) { var random = new Random(); var generator = new RandomGenerator(); var result = new BenchmarkResult(parameters); var tasks = new List<Task>(parameters.Num); long bytes = 0; for (var i = 0; i < parameters.Num; i += parameters.EntriesPerBatch) { var batch = new WriteBatch(); for (var j = 0; j < parameters.EntriesPerBatch; j++) { var k = seq ? i + j : random.Next() % options.Num; var key = string.Format("{0:0000000000000000}", k); batch.Put(key, generator.Generate(parameters.ValueSize)); bytes += parameters.ValueSize + key.Length; result.FinishOperation(); } tasks.Add(storage.Writer.WriteAsync(batch, new WriteOptions { FlushToDisk = parameters.Sync })); } result.AddBytes(bytes); return Task.WhenAll(tasks).ContinueWith(t => 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); }