bench.c (835B)
1 #include <stdio.h> 2 #include "sha3.h" 3 #include <stdlib.h> 4 #include <string.h> 5 #include <time.h> 6 7 #ifndef ROUNDS 8 #define ROUNDS 100000 9 #endif 10 11 void main() { 12 int rounds; 13 long delta_sec; 14 long delta_nsec; 15 struct timespec start; 16 struct timespec end; 17 18 int i; 19 char data[3] = {'f', 'o', 'o'}; 20 21 unsigned char buf[256]; 22 memset(buf, 0, 256); 23 24 for (i = 0; i < 100000; i++) { 25 sha3(data, 3, buf, 32); 26 } 27 28 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 29 for (i = 0; i < ROUNDS; i++) { 30 sha3(data, 3, buf, 32); 31 } 32 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 33 34 delta_sec = end.tv_sec - start.tv_sec; 35 delta_nsec = end.tv_nsec - start.tv_nsec; 36 if (delta_nsec < 0) { 37 delta_sec++; 38 delta_nsec += 1000000000L; 39 } 40 printf("%u.%09u\n", delta_sec, delta_nsec); 41 42 for (i = 0; i < 32; i++) { 43 printf("%02x", buf[i]); 44 } 45 printf("\n"); 46 }