manbytesgnu_site

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

bench.c (1247B)


      1 #include <stdio.h>
      2 #include <time.h>
      3 #include "libkeccak.h"
      4 
      5 #define BITRATE 1088
      6 #define CAPACITY 512
      7 #define OUTPUT 256
      8 
      9 #ifndef ROUNDS 
     10 #define ROUNDS 100000
     11 #endif
     12 
     13 void main() {
     14 	struct timespec start;
     15 	struct timespec end;
     16 
     17 	struct libkeccak_spec spec;
     18 	struct libkeccak_state state;
     19 
     20 	unsigned char buf[32];
     21 	char msg[3] = {'f', 'o', 'o'};
     22 	int i;
     23 	int r;
     24 
     25 	long delta_sec;
     26 	long delta_nsec;
     27 
     28 	spec.bitrate = BITRATE;
     29 	spec.capacity = CAPACITY;
     30 	spec.output = OUTPUT;
     31 
     32 	libkeccak_state_initialise(&state, &spec);
     33 
     34 	for (i = 0; i < 100; i++) {
     35 		libkeccak_state_initialise(&state, &spec);
     36 		libkeccak_fast_update(&state, msg, 3);
     37 		libkeccak_fast_digest(&state, NULL, 0, 0, NULL, buf);
     38 	}
     39 
     40 	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
     41 	for (i = 0; i < ROUNDS; i++) {
     42 		libkeccak_state_initialise(&state, &spec);
     43 		libkeccak_fast_update(&state, msg, 3);
     44 		libkeccak_fast_digest(&state, NULL, 0, 0, NULL, buf);
     45 	}
     46 	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
     47 
     48 	delta_sec = end.tv_sec - start.tv_sec;
     49 	delta_nsec = end.tv_nsec - start.tv_nsec;
     50 	if (delta_nsec < 0) {
     51 		delta_sec++;
     52 		delta_nsec += 1000000000L;
     53 	}
     54 	printf("%u.%09u\n", delta_sec, delta_nsec);
     55 
     56 	for (i = 0; i < 32; i++) {
     57 		printf("%02x", buf[i]);
     58 	}
     59 
     60 	printf("\n");
     61 
     62 }