-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
namespace MicroBenchmark; | ||
|
||
[MemoryDiagnoser] | ||
// [ShortRunJob] | ||
Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / check
Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (latest)
Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (v2.9)
Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (main)
Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Linux (latest)
Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Linux (main)
Check warning on line 11 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Linux (v2.9)
|
||
[PlainExporter] | ||
public class KVBench | ||
{ | ||
|
@@ -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 GitHub Actions / check
Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (latest)
Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (v2.9)
Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (main)
Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Linux (latest)
Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Linux (main)
Check warning on line 63 in sandbox/MicroBenchmark/KVBench.cs 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; | ||
} | ||
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 GitHub Actions / check
Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (latest)
Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (v2.9)
Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Windows (main)
Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Linux (latest)
Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs GitHub Actions / Linux (main)
Check warning on line 77 in sandbox/MicroBenchmark/KVBench.cs 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; | ||
// } | ||
} |