public void BenchmarkHops(int reps) {
List<int> hops = new List<int>();
Random my_r = new Random();
ArrayList nodes = null;
lock(_sync) {
//Make a copy
nodes = new ArrayList(_node_list);
}
Stack<Action> pings = new Stack<Action>();
for(int i = 0; i < reps; i++) {
int idx0 = my_r.Next(0, nodes.Count);
int idx1 = my_r.Next(0, nodes.Count);
Node n0 = (Node)nodes[idx0];
Node n1 = (Node)nodes[idx1];
Action ping = delegate() {
RpcManager pinger = n0.Rpc;
Channel results = new Channel(1);
results.CloseEvent += delegate(object q, EventArgs a) {
try {
object result = results.Dequeue();
RpcResult r = (RpcResult)result;
IList data = (IList)r.Result;
hops.Add(data.Count - 1);
}
catch(Exception x) {
Console.WriteLine("target: {0}, Exception: {1}", n1.Address, x);
}
if( pings.Count > 0 ) {
var next = pings.Pop();
next();
}
else {
double ave_rtt = 0;
foreach(int s in hops) {
ave_rtt += (double)s;
}
ave_rtt /= hops.Count;
double var = 0;
foreach(int s in hops) {
var += (ave_rtt - (double)s) * (ave_rtt - (double)s);
}
var /= hops.Count;
var stdev = Math.Sqrt(var);
Console.WriteLine("Average: {0} Stdev: {1} Samples: {2} Reps: {3}", ave_rtt, stdev, hops.Count, reps);
}
};
try {
pinger.Invoke(n0, results, "trace.GetRouteTo", n1.Address.ToString());
}
catch(Exception x) {
Console.WriteLine("Exception: {0}", x);
if( pings.Count > 0 ) {
var next = pings.Pop();
next();
}
else {
double ave_rtt = 0;
foreach(int s in hops) {
ave_rtt += (double)s;
}
ave_rtt /= hops.Count;
double var = 0;
foreach(int s in hops) {
var += (ave_rtt - (double)s) * (ave_rtt - (double)s);
}
var /= hops.Count;
var stdev = Math.Sqrt(var);
Console.WriteLine("Average: {0} Stdev: {1} Samples: {2} Reps: {3}", ave_rtt, stdev, hops.Count, reps);
}
}
};
pings.Push(ping);
}
//Now pop off the first one and go:
var first = pings.Pop();
first();
}
public void BenchmarkPing(int reps) {