-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Security.Cryptography; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Engines; | ||
using NewLife.Caching; | ||
using NewLife.Security; | ||
|
||
namespace Benchmark; | ||
|
||
[SimpleJob(RunStrategy.ColdStart, iterationCount: 1)] | ||
[MemoryDiagnoser] | ||
public class BasicBenchmark | ||
{ | ||
public FullRedis Redis { get; set; } | ||
|
||
private String[] _keys; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var rds = new FullRedis | ||
{ | ||
Tracer = DefaultTracer.Instance, | ||
Log = XTrace.Log, | ||
}; | ||
rds.Init("server=127.0.0.1:6379;password=;db=3;timeout=5000"); | ||
|
||
Redis = rds; | ||
|
||
var ks = new String[100_000]; | ||
for (var i = 0; i < ks.Length; i++) | ||
{ | ||
ks[i] = Rand.NextString(16); | ||
} | ||
_keys = ks; | ||
} | ||
|
||
[Benchmark] | ||
public void GetTest() | ||
{ | ||
var rds = Redis; | ||
|
||
for (var i = 0; i < _keys.Length; i++) | ||
{ | ||
var value = rds.Get<String>(_keys[i]); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void SetTest() | ||
{ | ||
var rds = Redis; | ||
var value = Rand.NextString(16); | ||
|
||
for (var i = 0; i < _keys.Length; i++) | ||
{ | ||
rds.Set(_keys[i], value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters