home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 509.lha / DES / src / benchmark.c next >
C/C++ Source or Header  |  1991-05-06  |  2KB  |  93 lines

  1. /* Just run DES in a loop consuming CPU time; good for benchmarking
  2.  * Phil Karn
  3.  * 
  4.         Time routines added as afterthought --SRP */
  5. #include <stdio.h>
  6. main()
  7. {
  8.     float seconds,seconds2;
  9.         long hours,minutes,hours2,minutes2,days,days2;
  10.  
  11.         struct time {
  12.         long days;
  13.         long minutes;
  14.         long ticks;
  15.     };
  16.     struct time w = {0,0,0};
  17.     struct time w2 = {0,0,0};
  18.  
  19.     char key[8],work[8];
  20.     long iter,count;
  21.  
  22.     desinit(0);
  23.     printf("Enter key (hex): ");
  24.     get8(key);
  25.     printf("Setting key: "); put8(key); printf("\n");
  26.     setkey(key);
  27.     printf("Enter starting value (hex): ");
  28.     get8(work);
  29.     printf("Starting value: "); put8(work); printf("\n");
  30.     printf("Number of iterations: ");
  31.     scanf("%ld",&count);
  32.  
  33.     DateStamp(&w);
  34.  
  35.     for(iter = 0;iter < count; iter++)
  36.         endes(work);
  37.  
  38.         DateStamp(&w2);
  39.  
  40.     printf("\nDONE.\n\n");
  41.  
  42.     days=(w.days);
  43.     seconds = (w.ticks) / 50.0;
  44.         hours = (w.minutes) / 60;
  45.         minutes= (w.minutes)-(hours * 60);
  46.  
  47.     days2=(w2.days);
  48.         seconds2 = ((w2.ticks) / 50.0);
  49.         hours2 = (w2.minutes) / 60;
  50.         minutes2= (w2.minutes)-(hours2 * 60);
  51.  
  52.     if(seconds > seconds2){
  53.         seconds2 += 60;
  54.         minutes2--;
  55.     }
  56.     if(minutes > minutes2){
  57.         minutes2 +=60;
  58.         hours2--;
  59.     }
  60.     if(hours > hours2){    
  61.         hours2 +=24;
  62.         days2--;
  63.     }
  64.     printf("Elapsed Time:\n\t %ld day(s) %ld hour(s) %ld minute(s) %.2f seconds\n",(days2-days), (hours2-hours), (minutes2-minutes), (seconds2-seconds)); 
  65.  
  66.  
  67.  
  68. }
  69. get8(cp)
  70. char *cp;
  71. {
  72.     int i,t;
  73.  
  74.     for(i=0;i<8;i++){
  75.         scanf("%2x",&t);
  76.         *cp++ = t;
  77.  
  78.  
  79.     }
  80. }
  81. put8(cp)
  82. char *cp;
  83. {
  84.     int i;
  85.  
  86.     for(i=0;i<8;i++){
  87.         printf("%2x ",*cp++ & 0xff);
  88.     }
  89. }
  90.  
  91.  
  92.  
  93.