/
Program.cs
65 lines (50 loc) · 2.07 KB
/
Program.cs
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
namespace ZeroMQ.Perf.ThrLocal
{
using System;
using System.Diagnostics;
using ZeroMQ;
internal class Program
{
internal static int Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("usage: local_thr <address> <message-size> <message-count>\n");
return 1;
}
string address = args[0];
int messageSize = Convert.ToInt32(args[1]);
int messageCount = Convert.ToInt32(args[2]);
if (messageSize <= 0 || messageCount <= 0)
{
Console.Error.WriteLine("message-size and message-count must be positive values.");
return 1;
}
long elapsedTime;
// Initialize 0MQ infrastructure
using (ZmqContext ctx = ZmqContext.Create())
using (ZmqSocket skt = ctx.CreateSocket(SocketType.PULL))
{
skt.Bind(address);
// Wait for the first message.
var msg = new byte[messageSize];
int receivedBytes = skt.Receive(msg);
Debug.Assert(receivedBytes == messageSize, "Received message did not have the expected length.");
Stopwatch watch = Stopwatch.StartNew();
// Receive all the remaining messages.
for (int i = 1; i < messageCount; i++)
{
receivedBytes = skt.Receive(msg);
Debug.Assert(receivedBytes == messageSize, "Received message did not have the expected length.");
}
watch.Stop();
elapsedTime = watch.ElapsedTicks;
}
long messageThroughput = messageCount * Stopwatch.Frequency / elapsedTime;
long megabitThroughput = messageThroughput * messageSize * 8 / 1000000;
Console.WriteLine("Average throughput: {0} [msg/s]", messageThroughput);
Console.WriteLine("Average throughput: {0} [Mb/s]", megabitThroughput);
return 0;
}
}
}