Commit 86039446 authored by Nick Craver's avatar Nick Craver

Cleanup: test programs

parent b0e6ac2e
......@@ -11,11 +11,9 @@
namespace BasicTest
{
static class Program
internal 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
{
......@@ -37,8 +35,8 @@ public CustomConfig()
[Config(typeof(CustomConfig))]
public class RedisBenchmarks : IDisposable
{
ConnectionMultiplexer connection;
IDatabase db;
private ConnectionMultiplexer connection;
private IDatabase db;
/// <summary>
/// Create
/// </summary>
......@@ -54,8 +52,7 @@ void IDisposable.Dispose()
connection = null;
}
const int COUNT = 10000;
private const int COUNT = 10000;
/// <summary>
/// Run INCRBY lots of times
......@@ -66,7 +63,7 @@ void IDisposable.Dispose()
[Benchmark(Description = "INCRBY:v2", OperationsPerInvoke = COUNT)]
#endif
public int Execute()
{
{
var rand = new Random(12345);
RedisKey counter = "counter";
db.KeyDelete(counter, CommandFlags.FireAndForget);
......@@ -78,8 +75,7 @@ public int Execute()
db.StringIncrement(counter, x, CommandFlags.FireAndForget);
}
int actual = (int)db.StringGet(counter);
if (actual != expected) throw new InvalidOperationException(
$"expected: {expected}, actual: {actual}");
if (actual != expected) throw new InvalidOperationException($"expected: {expected}, actual: {actual}");
return actual;
}
}
......
......@@ -12,14 +12,14 @@ namespace BasicTest
[Config(typeof(CustomConfig))]
public class TextBenchmarks
{
readonly string[] corpus;
readonly byte[] buffer;
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))];
}
static readonly Encoding enc = Encoding.UTF8;
private static readonly Encoding enc = Encoding.UTF8;
[Benchmark]
public long Measure()
......@@ -39,7 +39,7 @@ public long MeasureAndEncode()
string s = corpus[i];
total += enc.GetByteCount(s);
enc.GetBytes(s, 0, s.Length, buffer, 0);
}
}
return total;
}
[Benchmark]
......@@ -51,7 +51,6 @@ public long MeasureVectorized()
return total;
}
[Benchmark]
public long MeasureAndEncodeVectorized()
{
......@@ -66,9 +65,7 @@ public long MeasureAndEncodeVectorized()
return total;
}
static readonly Vector<ushort> NonAsciiMask = new Vector<ushort>(0xFF80);
private static readonly Vector<ushort> NonAsciiMask = new Vector<ushort>(0xFF80);
internal static
#if NET47
unsafe
......@@ -114,7 +111,7 @@ private int Encode(string value, byte[] buffer, int asciiChunks)
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++]);
......
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Pipelines;
using System.Linq;
using StackExchange.Redis;
class Program
namespace TestConsole
{
static int Main()
internal static class Program
{
var s = new StringWriter();
var watch = Stopwatch.StartNew();
try
private static int Main()
{
var s = new StringWriter();
var watch = Stopwatch.StartNew();
try
{
#if DEBUG
// Pipelines.Sockets.Unofficial.DebugCounters.SetLog(Console.Out);
// Pipelines.Sockets.Unofficial.DebugCounters.SetLog(Console.Out);
#endif
var config = new ConfigurationOptions
{
ConnectRetry = 0,
EndPoints = { "127.0.0.1:6381" },
Password = "abc",
};
using (var conn = ConnectionMultiplexer.Connect(config, log: s))
var config = new ConfigurationOptions
{
ConnectRetry = 0,
EndPoints = { "127.0.0.1:6381" },
Password = "abc",
};
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");
return 0;
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
return -1;
}
finally
{
watch.Stop();
Console.WriteLine();
Console.WriteLine($"{watch.ElapsedMilliseconds}ms");
Console.WriteLine();
finally
{
watch.Stop();
Console.WriteLine();
Console.WriteLine($"{watch.ElapsedMilliseconds}ms");
Console.WriteLine();
//Console.WriteLine(s);
Console.ReadKey();
//Console.WriteLine(s);
Console.ReadKey();
}
}
}
private static void Execute(ConnectionMultiplexer conn)
{
int pageSize = 100;
RedisKey key = nameof(Execute);
var db = conn.GetDatabase();
db.KeyDelete(key);
private static void Execute(ConnectionMultiplexer conn)
{
const int pageSize = 100;
RedisKey key = nameof(Execute);
var db = conn.GetDatabase();
db.KeyDelete(key);
for (int i = 0; i < 2000; i++)
db.SetAdd(key, "s" + i, flags: CommandFlags.FireAndForget);
for (int i = 0; i < 2000; i++)
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");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment