Skip to content

Commit

Permalink
Bench string
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmk committed Dec 6, 2024
1 parent 384a883 commit 99145a7
Show file tree
Hide file tree
Showing 2 changed files with 396 additions and 68 deletions.
174 changes: 106 additions & 68 deletions sandbox/MicroBenchmark/KVBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace MicroBenchmark;

[MemoryDiagnoser]
// [ShortRunJob]

Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / check

Single-line comment should be preceded by blank line

Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (latest)

Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (v2.9)

Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (main)

Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (latest)

Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (main)

Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (v2.9)

[PlainExporter]
public class KVBench
{
Expand All @@ -25,79 +26,116 @@ public async Task SetupAsync()
_store = (NatsKVStore)(await _kv.CreateStoreAsync("benchmark"));
}

[Benchmark]
public async ValueTask<int> TryGetAsync()
{
var result = await _store.TryGetEntryAsync<int>("does.not.exist");
if (result is { Success: false, Error: NatsKVKeyNotFoundException })
{
return 1;
}

return 0;
}
// [Benchmark(Baseline = true)]
// public async ValueTask<int> TryGetAsync()
// {
// var result = await _store.TryGetEntryAsync<int>("does.not.exist");
// if (result is { Success: false, Error: NatsKVKeyNotFoundException })
// {
// return 1;
// }
//
// return 0;
// }
//
// [Benchmark]
// public async ValueTask<int> TryGetAsync2()
// {
// var result = await _store.TryGetEntryAsync2<int>("does.not.exist");
// if (result is { Success: false, Error: NatsKVKeyNotFoundException })
// {
// return 1;
// }
//
// return 0;
// }
//
// [Benchmark]
// public async ValueTask<int> TryGetAsync3()
// {
// var result = await _store.TryGetEntryAsync3<int>("does.not.exist");
// if (result is { Success: false, Error: NatsKVKeyNotFoundException })
// {
// return 1;
// }
//
// return 0;
// }

Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / check

Single-line comments should not be followed by blank line

Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (v2.9)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (main)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (main)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (v2.9)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

[Benchmark(Baseline = true)]
public async ValueTask<int> GetAsync()
{
try
{
await _store.GetEntryAsync<int>("does.not.exist");
}
catch (NatsKVKeyNotFoundException)
{
return 1;
}

return 0;
}
public string StringOrig() => _store.StringOrig("does.not.exist");

[Benchmark]
public async ValueTask<int> TryGetMultiAsync()
{
List<Task> tasks = new();
for (var i = 0; i < 100; i++)
{
tasks.Add(Task.Run(async () =>
{
var result = await _store.TryGetEntryAsync<int>("does.not.exist");
if (result is { Success: false, Error: NatsKVKeyNotFoundException })
{
return 1;
}

return 0;
}));
}

await Task.WhenAll(tasks);

return 0;
}
public string StringInter() => _store.StringInter("does.not.exist");

[Benchmark]
public async ValueTask<int> GetMultiAsync()
{
List<Task> tasks = new();
for (var i = 0; i < 100; i++)
{
tasks.Add(Task.Run(async () =>
{
try
{
await _store.GetEntryAsync<int>("does.not.exist");
}
catch (NatsKVKeyNotFoundException)
{
return 1;
}
public string StringConcat() => _store.StringConcat("does.not.exist");

return 0;
}));
}

await Task.WhenAll(tasks);

return 0;
}
[Benchmark]
public string StringCreate() => _store.StringCreate("does.not.exist");

//

Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / check

Comments should contain text

Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (latest)

Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (v2.9)

Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Windows (main)

Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (latest)

Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (main)

Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs

View workflow job for this annotation

GitHub Actions / Linux (v2.9)

// [Benchmark(Baseline = true)]
// public async ValueTask<int> GetAsync()
// {
// try
// {
// await _store.GetEntryAsync<int>("does.not.exist");
// }
// catch (NatsKVKeyNotFoundException)
// {
// return 1;
// }
//
// return 0;
// }
//
// [Benchmark]
// public async ValueTask<int> TryGetMultiAsync()
// {
// List<Task> tasks = new();
// for (var i = 0; i < 100; i++)
// {
// tasks.Add(Task.Run(async () =>
// {
// var result = await _store.TryGetEntryAsync<int>("does.not.exist");
// if (result is { Success: false, Error: NatsKVKeyNotFoundException })
// {
// return 1;
// }
//
// return 0;
// }));
// }
//
// await Task.WhenAll(tasks);
//
// return 0;
// }
//
// [Benchmark]
// public async ValueTask<int> GetMultiAsync()
// {
// List<Task> tasks = new();
// for (var i = 0; i < 100; i++)
// {
// tasks.Add(Task.Run(async () =>
// {
// try
// {
// await _store.GetEntryAsync<int>("does.not.exist");
// }
// catch (NatsKVKeyNotFoundException)
// {
// return 1;
// }
//
// return 0;
// }));
// }
//
// await Task.WhenAll(tasks);
//
// return 0;
// }
}
Loading

0 comments on commit 99145a7

Please sign in to comment.