home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / bp_2_94 / vbwin / ccall / cbench / cbench2.c < prev   
C/C++ Source or Header  |  1994-01-24  |  8KB  |  282 lines

  1. /*****************************************************************************
  2.  
  3.  ----  C B E N C H  -------- C Benchmark Windows Application ----------------
  4.                              CBENCH.C: Complete C source of application
  5.  
  6. ==============================================================================
  7.  
  8. This is a small benchmark program which searchs different data types in a
  9. array.
  10.  
  11. ------------------------------------------------------------------------------
  12.  
  13. Copyright 1994 by Buchheit software research
  14.           Kronenstrasse 30, D-76133 Karlsruhe, Germany/Europe
  15.           Phone: +49 (0)721/37 67 76   Fax: +49 (0)721/35 62 38
  16.           Internet: mabu@buchheit.de   CompuServe: 100020,1723
  17.           All rights reserved.
  18.  
  19. Version:    1.00 of 93-Jan-25
  20. Programmer: Marcellus Buchheit
  21. System:     DOS 6.20, Windows (NT) 3.1
  22. Compiler:   Microsoft Visual-C++ 1.00
  23.  
  24. Change Report
  25. 93-Jan-25 1.00 mabu: initial version
  26.  
  27. *****************************************************************************/
  28.  
  29. #include <windows.h>
  30. #include <string.h>
  31.  
  32.  
  33. /*****************************************************************************
  34. P r i n t T i m e
  35. ==============================================================================
  36.  
  37. This function displays the specified time in milliseconds in a message box.
  38.  
  39. Parameters
  40.  ulTime   contains the time value in milliseconds.
  41.  pszType  points to the type of measuring.
  42.  
  43. *****************************************************************************/
  44.  
  45. void PrintTime(DWORD ulTime, char *pszType)
  46. {
  47.   char szBuf[200];
  48.   ulTime += 50; // round up/down by "/" and "%"
  49.   wsprintf(szBuf, "Ende der %s-Suche.\nZeit: %u.%02u Sek.",
  50.     pszType, (UINT)(ulTime / 1000), (UINT)(ulTime % 100));
  51.   MessageBox(0, szBuf, "C-Bench", MB_OK|MB_ICONINFORMATION);
  52. } /* PrintTime() */
  53.  
  54.  
  55. /*****************************************************************************
  56. S e a r c h D o u b l e
  57. ==============================================================================
  58.  
  59. This function searches a value in an array of double float values.
  60.  
  61. *****************************************************************************/
  62.  
  63. void SearchDouble()
  64. {
  65.   double afd[13];
  66.   long l;
  67.   int i;
  68.   DWORD ulTime;
  69.   // initialize array
  70.   afd[0] = 3.1415;
  71.   afd[1] = 6.283;
  72.   afd[2] = 12.566;
  73.   afd[3] = 25.132;
  74.   afd[4] = 50.264;
  75.   afd[5] = 100.528;
  76.   afd[6] = 201.056;
  77.   afd[7] = 402.112;
  78.   afd[8] = 804.224;
  79.   afd[9] = 1608.448;
  80.   afd[10] = 3216.896;
  81.   afd[11] = 6433.792;
  82.   afd[12] = 12867.584;
  83.   // start of measure
  84.   ulTime = GetTickCount();
  85.   for (l = 0; l < 200000; l++) {
  86.     double *pfd = afd;
  87.     for (i = 0; i < 13; i++, pfd++) {
  88.       if (*pfd == 2.718281) break;
  89.     } /* for (i) */
  90.   } /* for (l) */
  91.   ulTime = GetTickCount() - ulTime;
  92.   PrintTime(ulTime, "DOUBLE");
  93. } /* SearchDouble() */
  94.  
  95.  
  96. /*****************************************************************************
  97. S e a r c h F l o a t
  98. ==============================================================================
  99.  
  100. This function searches a value in an array of single precision float values.
  101.  
  102. *****************************************************************************/
  103.  
  104. void SearchFloat()
  105. {
  106.   float aft[13];
  107.   long l;
  108.   int i;
  109.   DWORD ulTime;
  110.   // initialize array
  111.   aft[0] = 3.1415f;
  112.   aft[1] = 6.283f;
  113.   aft[2] = 12.566f;
  114.   aft[3] = 25.132f;
  115.   aft[4] = 50.264f;
  116.   aft[5] = 100.528f;
  117.   aft[6] = 201.056f;
  118.   aft[7] = 402.112f;
  119.   aft[8] = 804.224f;
  120.   aft[9] = 1608.448f;
  121.   aft[10] = 3216.896f;
  122.   aft[11] = 6433.792f;
  123.   aft[12] = 12867.584f;
  124.   // start of measure
  125.   ulTime = GetTickCount();
  126.   for (l = 0; l < 200000; l++) {
  127.     float *pft = aft;
  128.     for (i = 0; i < 13; i++, pft++) {
  129.       if (*pft == 2.718281) break;
  130.     } /* for (i) */
  131.   } /* for (l) */
  132.   ulTime = GetTickCount() - ulTime;
  133.   PrintTime(ulTime, "FLOAT");
  134. } /* SearchFloat() */
  135.  
  136.  
  137. /*****************************************************************************
  138. S e a r c h S h o r t
  139. ==============================================================================
  140.  
  141. This function searches a value in an array of short integer (16 bit) values.
  142.  
  143. *****************************************************************************/
  144.  
  145. void SearchShort()
  146. {
  147.   short as[13];
  148.   long l;
  149.   int i;
  150.   DWORD ulTime;
  151.   // initialize array
  152.   as[0] = 4;
  153.   as[1] = 9;
  154.   as[2] = 19;
  155.   as[3] = 39;
  156.   as[4] = 79;
  157.   as[5] = 159;
  158.   as[6] = 319;
  159.   as[7] = 639;
  160.   as[8] = 1279;
  161.   as[9] = 2559;
  162.   as[10] = 5119;
  163.   as[11] = 10239;
  164.   as[12] = 20479;
  165.   // start of measure
  166.   ulTime = GetTickCount();
  167.   for (l = 0; l < 2000000; l++) {
  168.     short *ps = as;
  169.     for (i = 0; i < 13; i++, ps++) {
  170.       if (*ps == 12345) break;
  171.     } /* for (i) */
  172.   } /* for (l) */
  173.   ulTime = GetTickCount() - ulTime;
  174.   PrintTime(ulTime, "SHORT");
  175. } /* SearchShort() */
  176.  
  177.  
  178. /*****************************************************************************
  179. S e a r c h L o n g
  180. ==============================================================================
  181.  
  182. This function searches a value in an array of long integer (32 bit) values.
  183.  
  184. *****************************************************************************/
  185.  
  186. void SearchLong()
  187. {
  188.   long al[13];
  189.   long l;
  190.   int i;
  191.   DWORD ulTime;
  192.   // initialize array
  193.   al[0] = 262144;
  194.   al[1] = 524288;
  195.   al[2] = 1048576;
  196.   al[3] = 2097152;
  197.   al[4] = 4194304;
  198.   al[5] = 8388608;
  199.   al[6] = 16777216;
  200.   al[7] = 33554432;
  201.   al[8] = 67108864;
  202.   al[9] = 134217728;
  203.   al[10] = 268435456;
  204.   al[11] = 536870912;
  205.   al[12] = 1073741824;
  206.   // start of measure
  207.   ulTime = GetTickCount();
  208.   for (l = 0; l < 2000000; l++) {
  209.     long *pl = al;
  210.     for (i = 0; i < 13; i++, pl++) {
  211.       if (*pl == 1234567890) break;
  212.     } /* for (i) */
  213.   } /* for (l) */
  214.   ulTime = GetTickCount() - ulTime;
  215.   PrintTime(ulTime, "LONG");
  216. } /* SearchLong() */
  217.  
  218.  
  219. /*****************************************************************************
  220. S e a r c h S t r i n g
  221. ==============================================================================
  222.  
  223. This function searches a value in an array of string values.
  224.  
  225. *****************************************************************************/
  226.  
  227. void SearchString()
  228. {
  229.   char *apsz[13];
  230.   long l;
  231.   int i;
  232.   DWORD ulTime;
  233.   // initialize array
  234.   apsz[0] = "Buchheit";
  235.   apsz[1] = "Dudek";
  236.   apsz[2] = "Jung";
  237.   apsz[3] = "Kopf";
  238.   apsz[4] = "Kreisel";
  239.   apsz[5] = "Maslo";
  240.   apsz[6] = "Monadjemi";
  241.   apsz[7] = "Ramm";
  242.   apsz[8] = "Reinartz";
  243.   apsz[9] = "SteingrΣber";
  244.   apsz[10] = "Tischer";
  245.   apsz[11] = "Waldmeyer";
  246.   apsz[12] = "Zoschke";
  247.   // start of measure
  248.   ulTime = GetTickCount();
  249.   for (l = 0; l < 200000; l++) {
  250.     char **ppsz = apsz;
  251.     for (i = 0; i < 13; i++, ppsz++) {
  252.       if (!strcmp(*ppsz, "Gates")) break;
  253.     } /* for (i) */
  254.   } /* for (l) */
  255.   ulTime = GetTickCount() - ulTime;
  256.   PrintTime(ulTime, "STRING");
  257. } /* SearchString() */
  258.  
  259.  
  260. /*****************************************************************************
  261.  
  262.  ------------------------------- Main function ------------------------------
  263.  
  264. *****************************************************************************/
  265.  
  266. int PASCAL WinMain(HINSTANCE hiNew, HINSTANCE hiPrev, LPSTR pszCmdLine,
  267.   int idCmdShow)
  268. {
  269.   SearchString();
  270.   SearchShort();
  271.   SearchLong();
  272.   SearchFloat();
  273.   SearchDouble();
  274.   return 0;
  275. } /* WinMain() */
  276.  
  277.  
  278. /* ===================================
  279.    End of Windows Application CBENCH.C
  280.    ===================================
  281. */
  282.