Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / performance-tests / Throughput / client.cpp
bloba1e54de8a44aa60d2773c3e0696c860a628ad4c1
1 #include "TestC.h"
2 #include "ace/High_Res_Timer.h"
3 #include "ace/Get_Opt.h"
4 #include "tao/Strategies/advanced_resource.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 int message_size = 2048;
8 int message_count = 10 * 1024;
9 int test_runs = 6;
10 int do_shutdown = 0;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:b:i:n:x"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
25 case 'b':
26 message_size = ACE_OS::atoi (get_opts.opt_arg ());
27 break;
29 case 'i':
30 message_count = ACE_OS::atoi (get_opts.opt_arg ());
31 break;
33 case 'n':
34 test_runs = ACE_OS::atoi (get_opts.opt_arg ());
35 break;
37 case 'x':
38 do_shutdown = 1;
39 break;
41 case '?':
42 default:
43 ACE_ERROR_RETURN ((LM_ERROR,
44 "usage: %s "
45 "-k <ior> "
46 "-b <message_size> "
47 "-i <message_count> "
48 "-n <test_repetitions> "
49 "\n",
50 argv [0]),
51 -1);
53 // Indicates successful parsing of the command line
54 return 0;
57 int
58 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
60 try
62 CORBA::ORB_var orb =
63 CORBA::ORB_init (argc, argv);
65 if (parse_args (argc, argv) != 0)
66 return 1;
68 CORBA::Object_var tmp =
69 orb->string_to_object(ior);
71 Test::Receiver_Factory_var receiver_factory =
72 Test::Receiver_Factory::_narrow(tmp.in ());
74 if (CORBA::is_nil (receiver_factory.in ()))
76 ACE_ERROR_RETURN ((LM_DEBUG,
77 "Nil receiver factory reference <%s>\n",
78 ior),
79 1);
82 ACE_High_Res_Timer::global_scale_factor_type gsf =
83 ACE_High_Res_Timer::global_scale_factor ();
85 Test::Message message;
87 for (int j = 0; j != test_runs; ++j)
89 ACE_DEBUG ((LM_DEBUG,
90 "Testing with %d bytes per message\n",
91 message_size));
93 message.the_payload.length (message_size);
95 Test::Receiver_var receiver =
96 receiver_factory->create_receiver ();
98 ACE_hrtime_t start = ACE_OS::gethrtime ();
99 for (int i = 0; i != message_count; ++i)
101 message.message_id = i;
102 receiver->receive_data (message);
105 receiver->done ();
106 ACE_hrtime_t elapsed_time = ACE_OS::gethrtime () - start;
108 // convert to microseconds
109 ACE_UINT32 usecs = ACE_UINT32(elapsed_time / gsf);
111 double bytes =
112 (1000000.0 * message_count * message_size) / usecs;
113 double kbytes = bytes / 1024;
114 double mbytes = kbytes / 1024;
115 double mbits = bytes * 8 / 1000000;
117 ACE_DEBUG ((LM_DEBUG,
118 "Sender[%d] %f (bytes/sec), "
119 "%f (Kb/sec)\n"
120 "Sender[%d] %f (Mb/sec), %f Mbits\n",
121 message_size, bytes, kbytes,
122 message_size, mbytes, mbits));
124 message_size *= 2;
127 if (do_shutdown)
129 receiver_factory->shutdown ();
132 orb->destroy ();
134 catch (const CORBA::Exception& ex)
136 ex._tao_print_exception ("Exception caught:");
137 return 1;
140 return 0;