manbytesgnu_site

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

bench.c (914B)


      1 #include <string.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <time.h>
      5 #include "keccak-tiny.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 	//unsigned char *buf;
     20 	char data[3] = {'f', 'o', 'o'};
     21 
     22 	//buf = malloc(256);
     23 	unsigned char buf[256];
     24 	memset(buf, 0, 256);
     25 
     26 	for (i = 0; i < 10000; i++) {
     27 		hash(buf, 32, data, 3, 200-64, 0x01);
     28 	}
     29 
     30 	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
     31 	for (i = 0; i < ROUNDS; i++) {
     32 		hash(buf, 32, data, 3, 200-64, 0x01);
     33 	}
     34 	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
     35 
     36 	delta_sec = end.tv_sec - start.tv_sec;
     37 	delta_nsec = end.tv_nsec - start.tv_nsec;
     38 	if (delta_nsec < 0) {
     39 		delta_sec++;
     40 		delta_nsec += 1000000000L;
     41 	}
     42 	printf("%u.%09u\n", delta_sec, delta_nsec);
     43 
     44 	for (i = 0; i < 32; i++) {
     45 		printf("%02x", buf[i]);
     46 	}
     47 	printf("\n");
     48 }