forked from StackExchange/StackExchange.Redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (68 loc) · 2.4 KB
/
Copy pathProgram.cs
File metadata and controls
73 lines (68 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using StackExchange.Redis;
[assembly: AssemblyVersion("1.0.0")]
namespace BasicTest
{
class Program
{
static void Main(string[] args)
{
int AsyncOpsQty = 10000;
if(args.Length == 1)
{
int tmp;
if(int.TryParse(args[0], out tmp))
AsyncOpsQty = tmp;
}
MassiveBulkOpsAsync(AsyncOpsQty, true, true);
MassiveBulkOpsAsync(AsyncOpsQty, true, false);
MassiveBulkOpsAsync(AsyncOpsQty, false, true);
MassiveBulkOpsAsync(AsyncOpsQty, false, false);
}
static void MassiveBulkOpsAsync(int AsyncOpsQty, bool preserveOrder, bool withContinuation)
{
using (var muxer = ConnectionMultiplexer.Connect("localhost,resolvedns=1"))
{
muxer.PreserveAsyncOrder = preserveOrder;
RedisKey key = "MBOA";
var conn = muxer.GetDatabase();
muxer.Wait(conn.PingAsync());
#if DNXCORE50
int number = 0;
#endif
Action<Task> nonTrivial = delegate
{
#if !DNXCORE50
Thread.SpinWait(5);
#else
for (int i = 0; i < 50; i++)
{
number++;
}
#endif
};
var watch = Stopwatch.StartNew();
for (int i = 0; i <= AsyncOpsQty; i++)
{
var t = conn.StringSetAsync(key, i);
if (withContinuation) t.ContinueWith(nonTrivial);
}
int val = (int)muxer.Wait(conn.StringGetAsync(key));
watch.Stop();
Console.WriteLine("After {0}: {1}", AsyncOpsQty, val);
Console.WriteLine("({3}, {4})\r\n{2}: Time for {0} ops: {1}ms; ops/s: {5}", AsyncOpsQty, watch.ElapsedMilliseconds, Me(),
withContinuation ? "with continuation" : "no continuation", preserveOrder ? "preserve order" : "any order",
AsyncOpsQty / watch.Elapsed.TotalSeconds);
}
}
protected static string Me([CallerMemberName] string caller = null)
{
return caller;
}
}
}