diff --git a/src/progaudi.tarantool.benchmark/IncrementBatchBenchmark.cs b/src/progaudi.tarantool.benchmark/IncrementBatchBenchmark.cs new file mode 100644 index 00000000..87746f95 --- /dev/null +++ b/src/progaudi.tarantool.benchmark/IncrementBatchBenchmark.cs @@ -0,0 +1,35 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using BenchmarkDotNet.Attributes; +using ProGaudi.Tarantool.Client; +using StackExchange.Redis; + +namespace progaudi.tarantool.benchmark +{ + [Config(typeof(BenchmarkConfig))] + public class IncrementBatchBenchmark + { + private readonly Box _box; + private readonly IDatabaseAsync _redis; + private readonly int _batchSize; + private readonly ISpace _space; + + public IncrementBatchBenchmark() + { + _box = Box.Connect("localhost", 3301).GetAwaiter().GetResult(); + _space = _box.Schema["benchmark"]; + _redis = ConnectionMultiplexer.Connect("localhost:6379").GetDatabase(); + _batchSize = 1000; + } + + [Benchmark(Baseline = true)] + public async Task Redis() => await Task.WhenAll(Enumerable.Range(0, _batchSize).Select(_ => _redis.StringIncrementAsync("test_for_benchmarking")).ToArray()); + + [Benchmark] + public async Task Call() => await Task.WhenAll(Enumerable.Range(0, _batchSize).Select(_ => _box.Call("test_for_benchmarking")).ToArray()); + + [Benchmark] + public async Task Select() => await Task.WhenAll(Enumerable.Range(0, _batchSize).Select(_ => _space.Select, (int, int, string, string, string)>(ValueTuple.Create(1))).ToArray()); + } +} \ No newline at end of file diff --git a/src/progaudi.tarantool.benchmark/Program.cs b/src/progaudi.tarantool.benchmark/Program.cs index b676c60f..e51a3bf6 100644 --- a/src/progaudi.tarantool.benchmark/Program.cs +++ b/src/progaudi.tarantool.benchmark/Program.cs @@ -4,6 +4,6 @@ namespace progaudi.tarantool.benchmark { public static class Program { - public static void Main() => BenchmarkRunner.Run(); + public static void Main() => BenchmarkRunner.Run(); } } diff --git a/tarantool/testdata.lua b/tarantool/testdata.lua index a3182235..bbf26bcb 100644 --- a/tarantool/testdata.lua +++ b/tarantool/testdata.lua @@ -12,6 +12,10 @@ local function create_spaces_and_indecies() space3 = box.schema.space.create('with_scalar_index', { if_not_exists = true }) space3:create_index('primary', {type='tree', parts={1, 'scalar'}, if_not_exists = true}) + + box.schema.space.create('benchmark', { if_not_exists = true }) + box.space.benchmark:create_index('primary', {type='hash', parts={1, 'unsigned'}, if_not_exists = true}) + box.space.benchmark:insert{1, 2, "sdsdfgasd", "qweqweqweqweqwwe", "asdfasdfasdfasdfasdfasdfsadf"} end local function init()