home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / TestTools / Sources / TestTimings.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  3.9 KB  |  174 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TestTimings.cp
  3.  
  4.     Contains:    Implementation of class TTestTimings
  5.  
  6.     Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #ifndef __TESTTIMINGS__
  11. #include "TestTimings.h"
  12. #endif
  13. #ifndef __MISCTESTS__
  14. #include "MiscTests.h"
  15. #endif
  16.  
  17. class THelper : public TSimpleDynamic
  18. {
  19.     public:
  20.                     THelper();
  21.                     ~_CDECL THelper();
  22. };
  23.  
  24. THelper::THelper()
  25. {}
  26.  
  27. THelper::~THelper()
  28. {}
  29.  
  30. TTestTimings::TTestTimings()
  31. {}
  32.  
  33. TTestTimings::~TTestTimings()
  34. {}
  35.  
  36. void TTestTimings::InitTest(BooleanParm, BooleanParm, int, char**)
  37. {}
  38.  
  39. void TTestTimings::EndTest(BooleanParm, BooleanParm)
  40. {}
  41.  
  42. void StandardFunction(void*)
  43. {}
  44.  
  45. void TTestTimings::RunTestIteration(BooleanParm, BooleanParm)
  46. {
  47.     Boolean            ok = true;
  48.     unsigned long    elapsed;
  49.     size_t            idx;
  50.     unsigned long    overhead;
  51.     
  52.     {
  53.         TStopwatch watch;
  54.         for (idx = 0; idx < 10000; ++idx)
  55.         {    
  56.         }
  57.         elapsed = (&watch)->ElapsedMicroseconds();
  58.         unsigned long msec = elapsed/10000;
  59.         unsigned long rest = ((elapsed % 10000))/10;
  60.         Printf("### INFO: Loop overhead = %lu.%03lu Microseconds call\n",
  61.                 msec, rest);
  62.         overhead = elapsed;
  63.     }
  64.     {
  65.         TStopwatch watch;
  66.         for (idx = 0; idx < 10000; ++idx)
  67.         {
  68.             StandardFunction(&watch);
  69.         }
  70.         elapsed = (&watch)->ElapsedMicroseconds() - overhead;
  71.         unsigned long msec = elapsed/10000;
  72.         unsigned long rest = ((elapsed % 10000))/10;
  73.         Printf("### INFO: It took %lu.%03lu Microseconds per normal \"C\" Function call\n",
  74.                 msec, rest);
  75.     }
  76.     {
  77.         TStopwatch watch;
  78.         for (idx = 0; idx < 10000; ++idx)
  79.         {
  80.             THelper    test;
  81.         }
  82.         elapsed = (&watch)->ElapsedMicroseconds() - overhead;
  83.         unsigned long msec = elapsed/10000;
  84.         unsigned long rest = ((elapsed % 10000))/10;
  85.         Printf("### INFO: It took %lu.%03lu Microseconds per normal constructor/destructor pair\n",
  86.                 msec, rest);
  87.     }
  88.     {
  89.         {
  90.             TTimings    foo;
  91.         }
  92.         TStopwatch watch;
  93.         for (idx = 0; idx < 10000; ++idx)
  94.         {
  95.             TTimings    test;
  96.         }
  97.         elapsed = (&watch)->ElapsedMicroseconds() - overhead;
  98.         unsigned long msec = elapsed/10000;
  99.         unsigned long rest = ((elapsed % 10000))/10;
  100.         Printf("### INFO: It took %lu.%03lu Microseconds per shared constructor/destructor pair in \"thrash\" mode\n",
  101.                 msec, rest);
  102.     }
  103.     {
  104.         TTimings    foo;
  105.         TStopwatch watch;
  106.         for (idx = 0; idx < 10000; ++idx)
  107.         {
  108.             TTimings    test;
  109.         }
  110.         elapsed = (&watch)->ElapsedMicroseconds() - overhead;
  111.         unsigned long msec = elapsed/10000;
  112.         unsigned long rest = ((elapsed % 10000))/10;
  113.         Printf("### INFO: It took %lu.%03lu Microseconds per shared constructor/destructor pair\n",
  114.                 msec, rest);
  115.     }
  116.     {
  117.         TTimings    foo;
  118.         (&foo)->VirtualFunc();
  119.         TStopwatch watch;
  120.         for (idx = 0; idx < 10000; ++idx)
  121.         {
  122.             (&foo)->VirtualFunc();
  123.         }
  124.         elapsed = (&watch)->ElapsedMicroseconds() - overhead;
  125.         unsigned long msec = elapsed/10000;
  126.         unsigned long rest = ((elapsed % 10000))/10;
  127.         Printf("### INFO: It took %lu.%03lu Microseconds per virtual function call\n",
  128.                 msec, rest);
  129.     }
  130.     {
  131.         TTimings    foo;
  132.         foo.VirtualFunc();
  133.         TStopwatch watch;
  134.         for (idx = 0; idx < 10000; ++idx)
  135.         {
  136.             foo.VirtualFunc();
  137.         }
  138.         elapsed = (&watch)->ElapsedMicroseconds() - overhead;
  139.         unsigned long msec = elapsed/10000;
  140.         unsigned long rest = ((elapsed % 10000))/10;
  141.         Printf("### INFO: It took %lu.%03lu Microseconds per virtual function stub call\n",
  142.                 msec, rest);
  143.     }
  144.     {
  145.         TTimings    foo;
  146.         foo.StaticFunc(&foo);
  147.         TStopwatch watch;
  148.         for (idx = 0; idx < 10000; ++idx)
  149.         {
  150.             foo.StaticFunc(&watch);
  151.         }
  152.         elapsed = (&watch)->ElapsedMicroseconds() - overhead;
  153.         unsigned long msec = elapsed/10000;
  154.         unsigned long rest = ((elapsed % 10000))/10;
  155.         Printf("### INFO: It took %lu.%03lu Microseconds per static function stub call\n",
  156.                 msec, rest);
  157.     }
  158.     {
  159.         TTimings    foo;
  160.         foo.Method();
  161.         TStopwatch watch;
  162.         for (idx = 0; idx < 10000; ++idx)
  163.         {
  164.             foo.Method();
  165.         }
  166.         elapsed = (&watch)->ElapsedMicroseconds() - overhead;
  167.         unsigned long msec = elapsed/10000;
  168.         unsigned long rest = ((elapsed % 10000))/10;
  169.         Printf("### INFO: It took %lu.%03lu Microseconds per method stub call\n",
  170.                 msec, rest);
  171.     }
  172.     
  173. }
  174.