TestPerf.cxx File Reference

#include <ctime>
#include <iostream>
#include "MessageService/MsgFormat.h"
#include "MessageService/MsgService.h"

Go to the source code of this file.

Functions

 CVSID ("$Id: TestPerf.cxx,v 1.1 2001/02/21 17:30:17 buckley Exp $")
static void usage ()
int main (int argc, char **argv)

Function Documentation

CVSID ( "$Id: TestPerf.  cxx,
v 1.1 2001/02/21 17:30:17 buckley Exp $"   
)
int main ( int  argc,
char **  argv 
)

Definition at line 38 of file TestPerf.cxx.

References MsgService::GetStream(), MsgService::Instance(), Msg::kDebug, Msg::kInfo, Msg::kVerbose, MSG, n, MsgStream::SetLogLevel(), and usage().

00039 {
00040   register int i;
00041   int ntrials;
00042   int n = 999;
00043   float x = 999.999;
00044 
00045   if (argc == 1 || strstr(argv[1], "h")!=0) usage();
00046 
00047   ntrials = atoi(argv[1]);
00048 
00049   // Test sending messages to cout
00050   clock_t tcout1 = clock();
00051   for (i=0; i<ntrials; ++i) {
00052     cout << "A message " << n << x << "\n";
00053   }
00054   clock_t tcout2 = clock();
00055 
00056   // Test sending messages to cerr
00057   clock_t tcerr1 = clock();
00058   for (i=0; i<ntrials; ++i) {
00059     cerr << "A message " << n << x << "\n";
00060   }
00061   clock_t tcerr2 = clock();
00062 
00063   MsgService::Instance()->GetStream("Prf")->SetLogLevel(Msg::kDebug);
00064 
00065   // Test sending messages to cout through the message service
00066   clock_t tmsgcout1 = clock();
00067   for (i=0; i<ntrials; ++i) {
00068     MSG("Prf", Msg::kInfo) << "A message " << n << x << "\n";
00069   }
00070   clock_t tmsgcout2 = clock();
00071 
00072   // Test sending messages to cerr through the message service
00073   clock_t tmsgcerr1 = clock();
00074   for (i=0; i<ntrials; ++i) {
00075     MSG("Prf", Msg::kDebug) << "A message " << n << x << "\n";
00076   }
00077   clock_t tmsgcerr2 = clock();
00078 
00079   // Test sending a message which doesn't get printed
00080   clock_t tmsgnone1 = clock();
00081   for (i=0; i<ntrials; ++i) {
00082     MSG("Prf", Msg::kVerbose) << "A message " << n << x << "\n";
00083   }
00084   clock_t tmsgnone2 = clock();
00085 
00086   float cps = (float)CLOCKS_PER_SEC;
00087   float tcout    = (tcout2 - tcout1) / cps;
00088   float tcerr    = (tcerr2 - tcerr1) / cps;
00089   float tmsgcout = (tmsgcout2 - tmsgcout1) / cps;
00090   float tmsgcerr = (tmsgcerr2 - tmsgcerr1) / cps;
00091   float tmsgnone = (tmsgnone2 - tmsgnone1) / cps;
00092   static MsgFormat flt("f8.3");
00093 
00094   // Results
00095 
00096   cout << "    cout     : " << flt(tcout) << " seconds / " 
00097        << ntrials << " messages.\n";
00098   cout << "MSG cout     : " << flt(tmsgcout) << " seconds / " 
00099        << ntrials << " messages.\n\n";
00100 
00101   cout << "    cerr     : " << flt(tcerr) << " seconds / " 
00102        << ntrials << " messages.\n";
00103   cout << "MSG cerr     : " << flt(tmsgcerr) << " seconds / " 
00104        << ntrials << " messages.\n\n";
00105 
00106   cout << "MSG unprinted: " << flt(tmsgnone) << " seconds / " 
00107        << ntrials << " messages.\n";
00108   
00109   return EXIT_SUCCESS;
00110 }

static void usage (  )  [static]

Definition at line 31 of file TestPerf.cxx.

References exit().

Referenced by main().

00031                     {
00032   cerr << "usage: >testPerf n where n = #trials\n";
00033   exit(1);
00034 }


Generated on 3 Dec 2018 for loon by  doxygen 1.6.1