Advertisement
micha_b

cpucalc.c - get cputime for a series of calculation on Amiga m68k, using vbcc

Oct 1st, 2023
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.46 KB | Fixit | 0 0
  1. /*
  2.     cpucalc.c - an Amiga C compiler benchmark
  3.    
  4.     measures CPU time usage for 5.000.000 looped runs
  5.     through log(index)
  6.          
  7.     (c) Michael Bergmann 01-10-2023
  8.    
  9.     COMPILE:
  10.                 sc math=standard optimize opttime optloop noicon cpucalc.c link to cpucalc_sc
  11.                 vc +aos68k -v -c99 -lmieee -lauto -o cpucalc_vc cpucalc.c
  12.                 gcc -Wall -lm -lauto -Os -o cpucalc_gcc_ix cpucalc.c
  13.                 dcc -3.1 -vv -lm cpucalc.c -o cpucalc_dcc
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <math.h>
  20. #include <time.h>
  21.  
  22. #include <exec/types.h>
  23. #include <proto/exec.h>
  24.  
  25. char *vers="\0$VER: cpuCalc v1.0 (01.10.2023)";  /* Version string */
  26. char *stacksize = "$STACK:8192";                 /* only works when started from CLI */
  27.  
  28. /* Function proto types */
  29. STRPTR identifyCompiler(void);
  30. int main(void);
  31.  
  32. /*
  33.  * Function: identifyCompiler()
  34.  * Purose: Collect compiler system informations
  35.  */
  36. STRPTR identifyCompiler(void)
  37. {
  38.     char myCompiler[512];
  39.  
  40.     #ifdef __SASC
  41.         const int sasversion = __VERSION__;
  42.         const int sasrev = __REVISION__;
  43.     #endif
  44.    
  45.     #if defined(__STORM__)
  46.         /* Compiler is StormC3 */
  47.         sprintf(myCompiler, "StormC3");
  48.     #elif defined(__STORMGCC__)
  49.         /* Compiler is StormGCC4 */
  50.         sprintf(myCompiler, "GNU gcc, StormC4 flavour");
  51.     #elif defined(__MAXON__)
  52.         /* Compiler is Maxon/HiSoft C++ */
  53.         sprintf(myCompiler, "Maxon/HiSoft C++");
  54.     #elif defined(__GNUC__)
  55.         /* Compiler is gcc */
  56.         sprintf(myCompiler, "GNU gcc v%ld.%ld", __GNUC__, __GNUC_MINOR__);
  57.         #ifdef __GNUC_PATCHLEVEL__
  58.             strcat(myCompiler, ".");
  59.             strcat(myCompiler, __GNUC_PATCHLEVEL__);
  60.         #endif
  61.     #elif defined(__VBCC__)
  62.         /* Compiler is vbcc */
  63.         sprintf(myCompiler, "vbcc - Volker Barthelmann's retargetable C compiler");
  64.     #elif defined(__SASC)
  65.         /* Compiler is SAS/C */
  66.         sprintf(myCompiler, "SAS/C, Version %ld.%ld", sasversion, sasrev);
  67.     #elif defined(LATTICE)
  68.         /* Compiler is Lattice C */
  69.         sprintf(myCompiler, "Lattice C");
  70.     #elif defined(AZTEC_C)
  71.         /* Compiler is Aztec C */
  72.         sprintf(myCompiler, "Manx Aztec C v%ld", __VERSION);
  73.     #elif defined(_DCC)
  74.         /* Compiler is dice */
  75.         sprintf(myCompiler, "Matt Dillon's DICE, propably v3.15");
  76.     #else
  77.         /* Compiler not identified */
  78.         sprintf(myCompiler, "UNKNOWN");
  79.     #endif 
  80.     return(myCompiler);
  81. }
  82.  
  83. int main(void)
  84. {
  85.     clock_t start, end; /* measure CPU time */
  86.     double index;       /* index used for log() */
  87.     double result;      /* resulting CPU consumption */
  88.    
  89.     printf("----------------------------------------------------------\n");
  90.     printf("  ** Calculating CPU time as a C compiler benchmark ** \n");
  91.     printf("----------------------------------------------------------\n");
  92.     printf("Tested Compiler System: %s\n", identifyCompiler() );
  93.    
  94.     /* -- Start timer -- */
  95.     start = clock();
  96.     printf("\nTest START: %ld\n", start);
  97.    
  98.     /* stress routine */
  99.     for ( index = 1.0; index <= 5000000.0; ++index )
  100.         (void) log(index);
  101.        
  102.     /* -- Stop timer -- */  
  103.     end = clock();
  104.     printf("Test END: %ld\n", end);
  105.     printf("CLOCKS_PER_SEC = %d\n", CLOCKS_PER_SEC);
  106.     printf("Elapsed: %ld\n", end - start);
  107.    
  108.     /* -- calculate time diference and print it out -- */  
  109.     result = (double) ( ((double)end - (double)start) / (double)CLOCKS_PER_SEC);
  110.     printf("\nCPU time used: %3.3f sec.\n\n", result );  
  111.    
  112.     return 0;
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement