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
fc06d78c
Commit
fc06d78c
authored
Jul 10, 2018
by
Marc Gravell
Committed by
Nick Craver
Jul 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove vectors from basictest; it breaks *everything*
parent
0e428a7c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
9 additions
and
173 deletions
+9
-173
BasicTest.csproj
BasicTest/BasicTest.csproj
+0
-7
Program.cs
BasicTest/Program.cs
+1
-3
TextBenchmarks.cs
BasicTest/TextBenchmarks.cs
+0
-130
Program.cs
TestConsole/Program.cs
+6
-32
TestConsole.csproj
TestConsole/TestConsole.csproj
+2
-1
No files found.
BasicTest/BasicTest.csproj
View file @
fc06d78c
...
...
@@ -13,17 +13,10 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.14" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StackExchange.Redis\StackExchange.Redis.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="t8.shakespeare.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
BasicTest/Program.cs
View file @
fc06d78c
...
...
@@ -46,9 +46,7 @@ public class RedisBenchmarks : IDisposable
/// </summary>
public
RedisBenchmarks
()
{
mgr
=
new
SocketManager
(
GetType
().
Name
);
var
options
=
ConfigurationOptions
.
Parse
(
"127.0.0.1:6379,syncTimeout=1000"
);
options
.
SocketManager
=
mgr
;
var
options
=
ConfigurationOptions
.
Parse
(
"127.0.0.1:6379"
);
connection
=
ConnectionMultiplexer
.
Connect
(
options
);
db
=
connection
.
GetDatabase
(
3
);
}
...
...
BasicTest/TextBenchmarks.cs
deleted
100644 → 0
View file @
0e428a7c
using
System
;
using
System.IO
;
using
System.Linq
;
using
System.Numerics
;
using
System.Runtime.InteropServices
;
using
System.Text
;
using
BenchmarkDotNet.Attributes
;
#pragma warning disable CS1591
namespace
BasicTest
{
[
Config
(
typeof
(
CustomConfig
))]
public
class
TextBenchmarks
{
private
readonly
string
[]
corpus
;
private
readonly
byte
[]
buffer
;
public
TextBenchmarks
()
{
corpus
=
File
.
ReadAllLines
(
"t8.shakespeare.txt"
);
buffer
=
new
byte
[
enc
.
GetMaxByteCount
(
corpus
.
Max
(
x
=>
x
.
Length
))];
}
private
static
readonly
Encoding
enc
=
Encoding
.
UTF8
;
[
Benchmark
]
public
long
Measure
()
{
long
total
=
0
;
for
(
int
i
=
0
;
i
<
corpus
.
Length
;
i
++)
total
+=
enc
.
GetByteCount
(
corpus
[
i
]);
return
total
;
}
[
Benchmark
]
public
long
MeasureAndEncode
()
{
long
total
=
0
;
var
buffer
=
this
.
buffer
;
for
(
int
i
=
0
;
i
<
corpus
.
Length
;
i
++)
{
string
s
=
corpus
[
i
];
total
+=
enc
.
GetByteCount
(
s
);
enc
.
GetBytes
(
s
,
0
,
s
.
Length
,
buffer
,
0
);
}
return
total
;
}
[
Benchmark
]
public
long
MeasureVectorized
()
{
long
total
=
0
;
for
(
int
i
=
0
;
i
<
corpus
.
Length
;
i
++)
total
+=
GetEncodedLength
(
corpus
[
i
],
out
_
);
return
total
;
}
[
Benchmark
]
public
long
MeasureAndEncodeVectorized
()
{
long
total
=
0
;
var
buffer
=
this
.
buffer
;
for
(
int
i
=
0
;
i
<
corpus
.
Length
;
i
++)
{
string
s
=
corpus
[
i
];
total
+=
GetEncodedLength
(
s
,
out
var
asciiChunks
);
Encode
(
s
,
buffer
,
asciiChunks
);
}
return
total
;
}
private
static
readonly
Vector
<
ushort
>
NonAsciiMask
=
new
Vector
<
ushort
>(
0xFF80
);
internal
static
#if NET47
unsafe
#endif
int
GetEncodedLength
(
string
value
,
out
int
asciiChunks
)
{
asciiChunks
=
0
;
if
(
value
.
Length
==
0
)
return
0
;
int
offset
=
0
;
if
(
Vector
.
IsHardwareAccelerated
&&
value
.
Length
>=
Vector
<
ushort
>.
Count
)
{
var
charSpan
=
MemoryMarshal
.
Cast
<
char
,
Vector
<
ushort
>>(
value
.
AsSpan
());
var
nonAscii
=
NonAsciiMask
;
int
i
;
for
(
i
=
0
;
i
<
charSpan
.
Length
;
i
++)
{
if
((
charSpan
[
i
]
&
nonAscii
)
!=
Vector
<
ushort
>.
Zero
)
break
;
}
offset
=
Vector
<
ushort
>.
Count
*
i
;
asciiChunks
=
i
;
}
int
remaining
=
value
.
Length
-
offset
;
if
(
remaining
==
0
)
return
offset
;
// all ASCII (nice round length, and Vector support)
// handles a) no Vector support, b) anything from the fisrt non-ASCII chunk, c) tail end
#if NET47
fixed
(
char
*
ptr
=
value
)
{
return
offset
+
Encoding
.
UTF8
.
GetByteCount
(
ptr
+
offset
,
remaining
);
}
#else
return
offset
+
enc
.
GetByteCount
(
s
:
value
,
index
:
offset
,
count
:
remaining
);
#endif
}
private
int
Encode
(
string
value
,
byte
[]
buffer
,
int
asciiChunks
)
{
int
offset
=
0
;
if
(
Vector
.
IsHardwareAccelerated
&&
asciiChunks
!=
0
)
{
var
charSpan
=
MemoryMarshal
.
Cast
<
char
,
Vector
<
ushort
>>(
value
.
AsSpan
());
var
byteSpan
=
MemoryMarshal
.
Cast
<
byte
,
Vector
<
byte
>>(
buffer
);
var
nonAscii
=
NonAsciiMask
;
int
i
=
0
;
asciiChunks
>>=
1
;
// half it - we can only use double-chunks
for
(
int
chunk
=
0
;
chunk
<
asciiChunks
;
chunk
++)
{
byteSpan
[
chunk
]
=
Vector
.
Narrow
(
charSpan
[
i
++],
charSpan
[
i
++]);
}
offset
=
Vector
<
ushort
>.
Count
*
i
;
asciiChunks
=
i
;
}
int
remaining
=
value
.
Length
-
offset
;
if
(
remaining
==
0
)
return
offset
;
// all ASCII (nice round length, and Vector support)
// handles a) no Vector support, b) anything from the fisrt non-ASCII chunk, c) tail end
return
offset
+
enc
.
GetBytes
(
value
,
offset
,
remaining
,
buffer
,
offset
);
}
}
}
TestConsole/Program.cs
View file @
fc06d78c
using
System
;
using
System.Diagnostics
;
using
System.IO
;
using
StackExchange.Redis
;
namespace
TestConsole
{
...
...
@@ -9,46 +7,22 @@ internal static class Program
{
private
static
int
Main
()
{
var
s
=
new
StringWriter
();
var
watch
=
Stopwatch
.
StartNew
();
try
{
var
config
=
new
ConfigurationOptions
{
ConnectRetry
=
0
,
EndPoints
=
{
"127.0.0.1:6379"
},
};
using
(
var
conn
=
ConnectionMultiplexer
.
Connect
(
config
,
log
:
Console
.
Out
))
using
(
var
obj
=
new
BasicTest
.
RedisBenchmarks
())
{
Execute
(
conn
);
var
watch
=
Stopwatch
.
StartNew
();
obj
.
Execute
();
watch
.
Stop
();
Console
.
WriteLine
(
$"
{
watch
.
ElapsedMilliseconds
}
ms"
);
}
return
0
;
}
catch
(
Exception
ex
)
{
Console
.
Error
.
WriteLine
(
ex
);
Console
.
Error
.
WriteLine
(
ex
.
Message
);
return
-
1
;
}
finally
{
watch
.
Stop
();
Console
.
WriteLine
();
Console
.
WriteLine
(
$"
{
watch
.
ElapsedMilliseconds
}
ms (done)"
);
}
}
private
static
void
Execute
(
ConnectionMultiplexer
conn
)
{
Console
.
WriteLine
(
"Executing..."
);
var
key
=
"abc"
;
var
db
=
conn
.
GetDatabase
(
0
);
var
t
=
db
.
CreateTransaction
();
t
.
HashSetAsync
(
key
,
"foo"
,
"bar"
);
t
.
KeyExpireAsync
(
key
,
TimeSpan
.
FromSeconds
(
3600
));
t
.
Execute
();
Console
.
WriteLine
(
"Done"
);
}
}
}
TestConsole/TestConsole.csproj
View file @
fc06d78c
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.
1;net462
</TargetFrameworks>
<TargetFrameworks>netcoreapp2.
0;netcoreapp2.1;net47
</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
...
...
@@ -11,6 +11,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\BasicTest\BasicTest.csproj" />
<ProjectReference Include="..\StackExchange.Redis\StackExchange.Redis.csproj" />
</ItemGroup>
<ItemGroup>
...
...
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