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
86039446
Commit
86039446
authored
Jul 01, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: test programs
parent
b0e6ac2e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
65 deletions
+58
-65
Program.cs
BasicTest/Program.cs
+7
-11
TextBenchmarks.cs
BasicTest/TextBenchmarks.cs
+6
-9
Program.cs
TestConsole/Program.cs
+45
-45
No files found.
BasicTest/Program.cs
View file @
86039446
...
@@ -11,11 +11,9 @@
...
@@ -11,11 +11,9 @@
namespace
BasicTest
namespace
BasicTest
{
{
internal
static
class
Program
static
class
Program
{
{
static
void
Main
(
string
[]
args
)
=>
BenchmarkSwitcher
.
FromAssembly
(
typeof
(
Program
).
GetTypeInfo
().
Assembly
).
Run
(
args
);
private
static
void
Main
(
string
[]
args
)
=>
BenchmarkSwitcher
.
FromAssembly
(
typeof
(
Program
).
GetTypeInfo
().
Assembly
).
Run
(
args
);
}
}
internal
class
CustomConfig
:
ManualConfig
internal
class
CustomConfig
:
ManualConfig
{
{
...
@@ -37,8 +35,8 @@ public CustomConfig()
...
@@ -37,8 +35,8 @@ public CustomConfig()
[
Config
(
typeof
(
CustomConfig
))]
[
Config
(
typeof
(
CustomConfig
))]
public
class
RedisBenchmarks
:
IDisposable
public
class
RedisBenchmarks
:
IDisposable
{
{
ConnectionMultiplexer
connection
;
private
ConnectionMultiplexer
connection
;
IDatabase
db
;
private
IDatabase
db
;
/// <summary>
/// <summary>
/// Create
/// Create
/// </summary>
/// </summary>
...
@@ -54,8 +52,7 @@ void IDisposable.Dispose()
...
@@ -54,8 +52,7 @@ void IDisposable.Dispose()
connection
=
null
;
connection
=
null
;
}
}
private
const
int
COUNT
=
10000
;
const
int
COUNT
=
10000
;
/// <summary>
/// <summary>
/// Run INCRBY lots of times
/// Run INCRBY lots of times
...
@@ -66,7 +63,7 @@ void IDisposable.Dispose()
...
@@ -66,7 +63,7 @@ void IDisposable.Dispose()
[
Benchmark
(
Description
=
"INCRBY:v2"
,
OperationsPerInvoke
=
COUNT
)]
[
Benchmark
(
Description
=
"INCRBY:v2"
,
OperationsPerInvoke
=
COUNT
)]
#endif
#endif
public
int
Execute
()
public
int
Execute
()
{
{
var
rand
=
new
Random
(
12345
);
var
rand
=
new
Random
(
12345
);
RedisKey
counter
=
"counter"
;
RedisKey
counter
=
"counter"
;
db
.
KeyDelete
(
counter
,
CommandFlags
.
FireAndForget
);
db
.
KeyDelete
(
counter
,
CommandFlags
.
FireAndForget
);
...
@@ -78,8 +75,7 @@ public int Execute()
...
@@ -78,8 +75,7 @@ public int Execute()
db
.
StringIncrement
(
counter
,
x
,
CommandFlags
.
FireAndForget
);
db
.
StringIncrement
(
counter
,
x
,
CommandFlags
.
FireAndForget
);
}
}
int
actual
=
(
int
)
db
.
StringGet
(
counter
);
int
actual
=
(
int
)
db
.
StringGet
(
counter
);
if
(
actual
!=
expected
)
throw
new
InvalidOperationException
(
if
(
actual
!=
expected
)
throw
new
InvalidOperationException
(
$"expected:
{
expected
}
, actual:
{
actual
}
"
);
$"expected:
{
expected
}
, actual:
{
actual
}
"
);
return
actual
;
return
actual
;
}
}
}
}
...
...
BasicTest/TextBenchmarks.cs
View file @
86039446
...
@@ -12,14 +12,14 @@ namespace BasicTest
...
@@ -12,14 +12,14 @@ namespace BasicTest
[
Config
(
typeof
(
CustomConfig
))]
[
Config
(
typeof
(
CustomConfig
))]
public
class
TextBenchmarks
public
class
TextBenchmarks
{
{
readonly
string
[]
corpus
;
private
readonly
string
[]
corpus
;
readonly
byte
[]
buffer
;
private
readonly
byte
[]
buffer
;
public
TextBenchmarks
()
public
TextBenchmarks
()
{
{
corpus
=
File
.
ReadAllLines
(
"t8.shakespeare.txt"
);
corpus
=
File
.
ReadAllLines
(
"t8.shakespeare.txt"
);
buffer
=
new
byte
[
enc
.
GetMaxByteCount
(
corpus
.
Max
(
x
=>
x
.
Length
))];
buffer
=
new
byte
[
enc
.
GetMaxByteCount
(
corpus
.
Max
(
x
=>
x
.
Length
))];
}
}
static
readonly
Encoding
enc
=
Encoding
.
UTF8
;
private
static
readonly
Encoding
enc
=
Encoding
.
UTF8
;
[
Benchmark
]
[
Benchmark
]
public
long
Measure
()
public
long
Measure
()
...
@@ -39,7 +39,7 @@ public long MeasureAndEncode()
...
@@ -39,7 +39,7 @@ public long MeasureAndEncode()
string
s
=
corpus
[
i
];
string
s
=
corpus
[
i
];
total
+=
enc
.
GetByteCount
(
s
);
total
+=
enc
.
GetByteCount
(
s
);
enc
.
GetBytes
(
s
,
0
,
s
.
Length
,
buffer
,
0
);
enc
.
GetBytes
(
s
,
0
,
s
.
Length
,
buffer
,
0
);
}
}
return
total
;
return
total
;
}
}
[
Benchmark
]
[
Benchmark
]
...
@@ -51,7 +51,6 @@ public long MeasureVectorized()
...
@@ -51,7 +51,6 @@ public long MeasureVectorized()
return
total
;
return
total
;
}
}
[
Benchmark
]
[
Benchmark
]
public
long
MeasureAndEncodeVectorized
()
public
long
MeasureAndEncodeVectorized
()
{
{
...
@@ -66,9 +65,7 @@ public long MeasureAndEncodeVectorized()
...
@@ -66,9 +65,7 @@ public long MeasureAndEncodeVectorized()
return
total
;
return
total
;
}
}
private
static
readonly
Vector
<
ushort
>
NonAsciiMask
=
new
Vector
<
ushort
>(
0xFF80
);
static
readonly
Vector
<
ushort
>
NonAsciiMask
=
new
Vector
<
ushort
>(
0xFF80
);
internal
static
internal
static
#if NET47
#if NET47
unsafe
unsafe
...
@@ -114,7 +111,7 @@ private int Encode(string value, byte[] buffer, int asciiChunks)
...
@@ -114,7 +111,7 @@ private int Encode(string value, byte[] buffer, int asciiChunks)
var
nonAscii
=
NonAsciiMask
;
var
nonAscii
=
NonAsciiMask
;
int
i
=
0
;
int
i
=
0
;
asciiChunks
>>=
1
;
// half it - we can only use double-chunks
asciiChunks
>>=
1
;
// half it - we can only use double-chunks
for
(
int
chunk
=
0
;
chunk
<
asciiChunks
;
chunk
++)
for
(
int
chunk
=
0
;
chunk
<
asciiChunks
;
chunk
++)
{
{
byteSpan
[
chunk
]
=
Vector
.
Narrow
(
charSpan
[
i
++],
charSpan
[
i
++]);
byteSpan
[
chunk
]
=
Vector
.
Narrow
(
charSpan
[
i
++],
charSpan
[
i
++]);
...
...
TestConsole/Program.cs
View file @
86039446
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.IO
;
using
System.IO
;
using
System.IO.Pipelines
;
using
System.Linq
;
using
System.Linq
;
using
StackExchange.Redis
;
using
StackExchange.Redis
;
class
Program
namespace
TestConsole
{
{
static
int
Main
()
internal
static
class
Program
{
{
var
s
=
new
StringWriter
();
private
static
int
Main
()
var
watch
=
Stopwatch
.
StartNew
();
try
{
{
var
s
=
new
StringWriter
();
var
watch
=
Stopwatch
.
StartNew
();
try
{
#if DEBUG
#if DEBUG
// Pipelines.Sockets.Unofficial.DebugCounters.SetLog(Console.Out);
// Pipelines.Sockets.Unofficial.DebugCounters.SetLog(Console.Out);
#endif
#endif
var
config
=
new
ConfigurationOptions
var
config
=
new
ConfigurationOptions
{
{
ConnectRetry
=
0
,
ConnectRetry
=
0
,
EndPoints
=
{
"127.0.0.1:6381"
},
EndPoints
=
{
"127.0.0.1:6381"
},
Password
=
"abc"
,
Password
=
"abc"
,
};
};
using
(
var
conn
=
ConnectionMultiplexer
.
Connect
(
config
,
log
:
s
))
using
(
var
conn
=
ConnectionMultiplexer
.
Connect
(
config
,
log
:
s
))
{
Execute
(
conn
);
}
Console
.
WriteLine
(
"Clean exit"
);
return
0
;
}
catch
(
Exception
ex
)
{
{
Execute
(
conn
);
Console
.
Error
.
WriteLine
(
ex
);
return
-
1
;
}
}
Console
.
WriteLine
(
"Clean exit"
);
finally
return
0
;
{
}
watch
.
Stop
();
catch
(
Exception
ex
)
Console
.
WriteLine
();
{
Console
.
WriteLine
(
$"
{
watch
.
ElapsedMilliseconds
}
ms"
);
Console
.
Error
.
WriteLine
(
ex
);
Console
.
WriteLine
();
return
-
1
;
}
finally
{
watch
.
Stop
();
Console
.
WriteLine
();
Console
.
WriteLine
(
$"
{
watch
.
ElapsedMilliseconds
}
ms"
);
Console
.
WriteLine
();
//Console.WriteLine(s);
//Console.WriteLine(s);
Console
.
ReadKey
();
Console
.
ReadKey
();
}
}
}
}
private
static
void
Execute
(
ConnectionMultiplexer
conn
)
private
static
void
Execute
(
ConnectionMultiplexer
conn
)
{
{
int
pageSize
=
100
;
const
int
pageSize
=
100
;
RedisKey
key
=
nameof
(
Execute
);
RedisKey
key
=
nameof
(
Execute
);
var
db
=
conn
.
GetDatabase
();
var
db
=
conn
.
GetDatabase
();
db
.
KeyDelete
(
key
);
db
.
KeyDelete
(
key
);
for
(
int
i
=
0
;
i
<
2000
;
i
++)
for
(
int
i
=
0
;
i
<
2000
;
i
++)
db
.
SetAdd
(
key
,
"s"
+
i
,
flags
:
CommandFlags
.
FireAndForget
);
db
.
SetAdd
(
key
,
"s"
+
i
,
flags
:
CommandFlags
.
FireAndForget
);
int
count
=
db
.
SetScan
(
key
,
pageSize
:
pageSize
).
Count
();
int
count
=
db
.
SetScan
(
key
,
pageSize
:
pageSize
).
Count
();
Console
.
WriteLine
(
count
==
2000
?
"Pass"
:
"Fail"
);
Console
.
WriteLine
(
count
==
2000
?
"Pass"
:
"Fail"
);
}
}
}
}
}
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