home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / crackunx.txt / Sources / speeds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-25  |  1.8 KB  |  98 lines

  1. /*
  2.  * This program is copyright Alec Muffett 1991 except for some portions of
  3.  * code in "crack-fcrypt.c" which are copyright Robert Baldwin, Icarus Sparry
  4.  * and Alec Muffett. The author(s) disclaims all responsibility or liability
  5.  * with respect to it's usage or its effect upon hardware or computer
  6.  * systems, and maintain copyright as set out in the "LICENCE" document which
  7.  * accompanies distributions of Crack v4.0 and upwards.
  8.  */
  9.  
  10. /*  Cray portions Copyright (c) 1992 Tom Hutton. */
  11. #ifdef cray
  12. #include <sys/types.h>
  13. #include <time.h>
  14. #include <unistd.h>
  15. #include <ctype.h>
  16. #else
  17. #include <sys/time.h>
  18. #include <signal.h>
  19. #endif
  20. #include <stdio.h>
  21.  
  22. #ifdef cray
  23. /*
  24.  * Clocks to seconds and seconds to clocks
  25.  */
  26.  
  27. #define CTOS(X)  ((long) ((unsigned) (X) / (long) hz))
  28. #define STOC(X)  ((long) ((X) * hz))
  29.  
  30. static long hz;
  31. #endif
  32.  
  33. static int cnt;
  34. #define ITIME    10        /* Number of seconds to run test. */
  35.  
  36. void
  37. Stop ()
  38. {
  39.     printf ("Did %f %s()s per second.\n",
  40.         ((float) cnt) / ((float) ITIME),
  41. #ifdef T1
  42.         "fcrypt"
  43. #else
  44. #ifdef T2
  45.         "XForm"
  46. #else
  47.         "crypt"
  48. #endif
  49. #endif
  50.     );
  51.     exit (0);
  52. }
  53. main ()
  54. {
  55. #ifdef    cray
  56.     static long vtime;
  57. #else
  58.     struct itimerval itv;
  59. #endif
  60.     static int quarters[4];
  61.  
  62. #ifdef cray
  63.     hz = sysconf(_SC_CLK_TCK);      /* get # ticks per second */
  64.     vtime = STOC(ITIME);
  65. #else
  66.     bzero (&itv, sizeof (itv));
  67. #endif
  68.  
  69.     printf ("Running for %d seconds of virtual time ...\n", ITIME);
  70.  
  71. #if defined(T1) || defined(T2)
  72.     init_des ();
  73. #endif
  74.  
  75. #ifdef cray
  76.     for (cnt = 0;cpused() <= vtime; cnt++)
  77. #else
  78.     signal (SIGVTALRM, Stop);
  79.     itv.it_value.tv_sec = ITIME;
  80.     itv.it_value.tv_usec = 0;
  81.     setitimer (ITIMER_VIRTUAL, &itv, NULL);
  82.  
  83.     for (cnt = 0;; cnt++)
  84. #endif
  85.     {
  86. #ifdef T1
  87.     fcrypt ("fredfred", "eek");
  88. #else
  89. #ifdef T2
  90.     XForm (quarters, 0);
  91. #else
  92.     crypt ("fredfred", "eek");
  93. #endif
  94. #endif
  95.     }
  96.     Stop();
  97. }
  98.