manbytesgnu_site

Source files for manbytesgnu.org
git clone git://holbrook.no/manbytesgnu_site.git
Info | Log | Files | Refs

bench.c (933B)


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