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> 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> ReadMissing(BenchmarkParameters parameters)
		{
			var random = new Random();
			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 (storage.Reader.Read(key)) { }

				result.FinishOperation();
			}

			return Task.FromResult(result);
		}
		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> DoDelete(BenchmarkParameters parameters, bool seq)
		{
			var random = new Random();
			var result = new BenchmarkResult(parameters);

			var tasks = new List<Task>(parameters.Num);

			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.Delete(key);
					result.FinishOperation();
				}

				tasks.Add(storage.Writer.WriteAsync(batch));
			}

			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);
		}