Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
6b66c8c5
Commit
6b66c8c5
authored
Jul 17, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moar benchmark types
parent
287dc8f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
13 deletions
+84
-13
Program.cs
BasicTest/Program.cs
+81
-10
BasicTestBaseline.csproj
BasicTestBaseline/BasicTestBaseline.csproj
+2
-2
Program.cs
TestConsole/Program.cs
+1
-1
No files found.
BasicTest/Program.cs
View file @
6b66c8c5
using
System
;
using
System.Reflection
;
using
System.Threading.Tasks
;
using
BenchmarkDotNet.Attributes
;
using
BenchmarkDotNet.Columns
;
using
BenchmarkDotNet.Configs
;
...
...
@@ -21,8 +22,8 @@ internal class CustomConfig : ManualConfig
public
CustomConfig
()
{
Job
Get
(
Job
j
)
=>
j
.
With
(
new
GcMode
{
Force
=
true
})
.
With
(
InProcessToolchain
.
Instance
);
.
With
(
new
GcMode
{
Force
=
true
})
;
//
.With(InProcessToolchain.Instance);
Add
(
new
MemoryDiagnoser
());
Add
(
StatisticColumn
.
OperationsPerSecond
);
...
...
@@ -49,7 +50,12 @@ public RedisBenchmarks()
var
options
=
ConfigurationOptions
.
Parse
(
"127.0.0.1:6379"
);
connection
=
ConnectionMultiplexer
.
Connect
(
options
);
db
=
connection
.
GetDatabase
(
3
);
db
.
KeyDelete
(
GeoKey
,
CommandFlags
.
FireAndForget
);
db
.
GeoAdd
(
GeoKey
,
13.361389
,
38.115556
,
"Palermo "
);
db
.
GeoAdd
(
GeoKey
,
15.087269
,
37.502669
,
"Catania"
);
}
static
readonly
RedisKey
GeoKey
=
"GeoTest"
,
IncrByKey
=
"counter"
;
void
IDisposable
.
Dispose
()
{
mgr
?.
Dispose
();
...
...
@@ -59,31 +65,96 @@ void IDisposable.Dispose()
connection
=
null
;
}
private
const
int
COUNT
=
100
00
;
private
const
int
COUNT
=
5
00
;
/// <summary>
/// Run INCRBY lots of times
/// </summary>
#if TEST_BASELINE
[
Benchmark
(
Description
=
"INCRBY:v1"
,
OperationsPerInvoke
=
COUNT
)]
[
Benchmark
(
Description
=
"INCRBY:v1
/s
"
,
OperationsPerInvoke
=
COUNT
)]
#else
[
Benchmark
(
Description
=
"INCRBY:v2"
,
OperationsPerInvoke
=
COUNT
)]
[
Benchmark
(
Description
=
"INCRBY:v2
/s
"
,
OperationsPerInvoke
=
COUNT
)]
#endif
public
int
Execute
()
public
int
Execute
IncrBy
()
{
var
rand
=
new
Random
(
12345
);
RedisKey
counter
=
"counter"
;
db
.
KeyDelete
(
counter
,
CommandFlags
.
FireAndForget
);
db
.
KeyDelete
(
IncrByKey
,
CommandFlags
.
FireAndForget
);
int
expected
=
0
;
for
(
int
i
=
0
;
i
<
COUNT
;
i
++)
{
int
x
=
rand
.
Next
(
50
);
expected
+=
x
;
db
.
StringIncrement
(
counter
,
x
,
CommandFlags
.
FireAndForget
);
db
.
StringIncrement
(
IncrByKey
,
x
,
CommandFlags
.
FireAndForget
);
}
int
actual
=
(
int
)
db
.
StringGet
(
counter
);
int
actual
=
(
int
)
db
.
StringGet
(
IncrByKey
);
if
(
actual
!=
expected
)
throw
new
InvalidOperationException
(
$"expected:
{
expected
}
, actual:
{
actual
}
"
);
return
actual
;
}
/// <summary>
/// Run INCRBY lots of times
/// </summary>
#if TEST_BASELINE
[
Benchmark
(
Description
=
"INCRBY:v1/a"
,
OperationsPerInvoke
=
COUNT
)]
#else
[
Benchmark
(
Description
=
"INCRBY:v2/a"
,
OperationsPerInvoke
=
COUNT
)]
#endif
public
async
Task
<
int
>
ExecuteIncrByAsync
()
{
var
rand
=
new
Random
(
12345
);
db
.
KeyDelete
(
IncrByKey
,
CommandFlags
.
FireAndForget
);
int
expected
=
0
;
for
(
int
i
=
0
;
i
<
COUNT
;
i
++)
{
int
x
=
rand
.
Next
(
50
);
expected
+=
x
;
await
db
.
StringIncrementAsync
(
IncrByKey
,
x
,
CommandFlags
.
FireAndForget
);
}
int
actual
=
(
int
)
await
db
.
StringGetAsync
(
IncrByKey
);
if
(
actual
!=
expected
)
throw
new
InvalidOperationException
(
$"expected:
{
expected
}
, actual:
{
actual
}
"
);
return
actual
;
}
/// <summary>
/// Run GEORADIUS lots of times
/// </summary>
#if TEST_BASELINE
[
Benchmark
(
Description
=
"GEORADIUS:v1/s"
,
OperationsPerInvoke
=
COUNT
)]
#else
[
Benchmark
(
Description
=
"GEORADIUS:v2/s"
,
OperationsPerInvoke
=
COUNT
)]
#endif
public
int
ExecuteGeoRadius
()
{
int
total
=
0
;
for
(
int
i
=
0
;
i
<
COUNT
;
i
++)
{
var
results
=
db
.
GeoRadius
(
GeoKey
,
15
,
37
,
200
,
GeoUnit
.
Kilometers
,
options
:
GeoRadiusOptions
.
WithCoordinates
|
GeoRadiusOptions
.
WithDistance
|
GeoRadiusOptions
.
WithGeoHash
);
total
+=
results
.
Length
;
}
return
total
;
}
/// <summary>
/// Run GEORADIUS lots of times
/// </summary>
#if TEST_BASELINE
[
Benchmark
(
Description
=
"GEORADIUS:v1/a"
,
OperationsPerInvoke
=
COUNT
)]
#else
[
Benchmark
(
Description
=
"GEORADIUS:v2/a"
,
OperationsPerInvoke
=
COUNT
)]
#endif
public
async
Task
<
int
>
ExecuteGeoRadiusAsync
()
{
int
total
=
0
;
for
(
int
i
=
0
;
i
<
COUNT
;
i
++)
{
var
results
=
await
db
.
GeoRadiusAsync
(
GeoKey
,
15
,
37
,
200
,
GeoUnit
.
Kilometers
,
options
:
GeoRadiusOptions
.
WithCoordinates
|
GeoRadiusOptions
.
WithDistance
|
GeoRadiusOptions
.
WithGeoHash
);
total
+=
results
.
Length
;
}
return
total
;
}
}
}
BasicTestBaseline/BasicTestBaseline.csproj
View file @
6b66c8c5
...
...
@@ -3,9 +3,9 @@
<PropertyGroup>
<Description>StackExchange.Redis.BasicTest .NET Core</Description>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;net47</TargetFrameworks>
<AssemblyName>BasicTest</AssemblyName>
<AssemblyName>BasicTest
Baseline
</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>BasicTest</PackageId>
<PackageId>BasicTest
Baseline
</PackageId>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<LangVersion>latest</LangVersion>
...
...
TestConsole/Program.cs
View file @
6b66c8c5
...
...
@@ -12,7 +12,7 @@ private static int Main()
using
(
var
obj
=
new
BasicTest
.
RedisBenchmarks
())
{
var
watch
=
Stopwatch
.
StartNew
();
obj
.
Execute
();
obj
.
Execute
IncrBy
();
watch
.
Stop
();
Console
.
WriteLine
(
$"
{
watch
.
ElapsedMilliseconds
}
ms"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment