ICE 3.4.2
[php5-ice-freebsdport.git] / cs / demo / Ice / latency / Client.cs
blob36cfb08b3b454c54fa746c1087a8da64fabef38b
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 using Demo;
11 using System;
12 using System.Reflection;
14 [assembly: CLSCompliant(true)]
16 [assembly: AssemblyTitle("IceLatencyClient")]
17 [assembly: AssemblyDescription("Ice latency demo client")]
18 [assembly: AssemblyCompany("ZeroC, Inc.")]
20 public class Client
22 public class App : Ice.Application
24 public override int run(string[] args)
26 if(args.Length > 0)
28 Console.Error.WriteLine(appName() + ": too many arguments");
29 return 1;
32 PingPrx ping = PingPrxHelper.checkedCast(communicator().propertyToProxy("Ping.Proxy"));
33 if(ping == null)
35 Console.Error.WriteLine("invalid proxy");
36 return 1;
40 // A method needs to be invoked thousands of times before the JIT compiler
41 // will convert it to native code. To ensure an accurate latency measurement,
42 // we need to "warm up" the JIT compiler.
45 int reps = 20000;
46 Console.Error.Write("warming up the JIT compiler...");
47 Console.Error.Flush();
48 for(int i = 0; i < reps; i++)
50 ping.ice_ping();
52 Console.Error.WriteLine("ok");
55 DateTime tv1 = DateTime.Now;
56 int repetitions = 100000;
57 Console.Out.WriteLine("pinging server " + repetitions + " times (this may take a while)");
58 for (int i = 0; i < repetitions; i++)
60 ping.ice_ping();
63 double total = (double)(DateTime.Now - tv1).TotalMilliseconds;
64 double perPing = total / repetitions;
66 Console.Out.WriteLine("time for " + repetitions + " pings: " + total + "ms");
67 Console.Out.WriteLine("time per ping: " + perPing + "ms");
69 return 0;
73 public static int Main(string[] args)
75 App app = new App();
76 return app.main(args, "config.client");