2 * This fcrypt/crypt speed testing program
3 * is derived from one floating around in
4 * the net. It's distributed along with
5 * UFC-crypt but is not covered by any
8 * @(#)speeds.c 1.11 20 Aug 1996
16 * patch from chip@chinacat.unicom.com (Chip Rosenthal):
17 * you may enable it if your system does not include
18 * a setitimer() function. You'll have to ensure the
19 * existence a environment variable: HZ giving how many
20 * ticks goes per second.
21 * If not existing in your default environment 50, 60
22 * or even 100 may be the right value. Perhaps you should
23 * then use 'time ./ufc 10000' instead of guessing.
29 #include <sys/types.h>
30 #include <sys/times.h>
38 struct tms tstart
, tfinish
;
40 #define ITIME 10 /* Number of seconds to run test. */
42 char *crypt(), *fcrypt();
49 (void) times(&tfinish
);
50 elapsed
= ((tfinish
.tms_utime
+ tfinish
.tms_stime
) -
51 (tstart
.tms_utime
+ tstart
.tms_stime
)) / atoi(hz
);
52 printf("elapsed time = %d sec, CPU time = %f sec\n", ITIME
, elapsed
);
56 printf ("Did %f %s()s per second.\n", ((float) cnt
) / elapsed
,
67 * Silly rewrite of 'bzero'. I do so
68 * because some machines don't have
69 * bzero and some don't have memset.
72 static void clearmem(start
, cnt
)
83 extern char *getenv();
89 if ((hz
= getenv("HZ")) == NULL
) {
90 fprintf(stderr
, "HZ environment parameter undefined\n");
97 printf("Warning: this version of the speed program may run slower when\n");
98 printf("benchmarking UFC-crypt than previous versions. This is because it\n");
99 printf("stresses the CPU hardware cache in order to get benchmark figures\n");
100 printf("that corresponds closer to the performance that can be expected in\n");
101 printf("a password cracker.\n\n");
104 printf ("Running %s for %d seconds of virtual time ...\n",
117 signal(SIGALRM
, Stop
);
120 perror("fork failed");
124 kill(getppid(), SIGALRM
);
127 (void) times(&tstart
);
130 clearmem ((char*)&itv
, (int)sizeof (itv
));
131 signal (SIGVTALRM
, Stop
);
132 itv
.it_value
.tv_sec
= ITIME
;
133 itv
.it_value
.tv_usec
= 0;
134 setitimer (ITIMER_VIRTUAL
, &itv
, NULL
);
139 for (cnt
= 0;; cnt
++)
142 s
= fcrypt (s
, "eek");
144 s
= crypt (s
, "eek");