Home | History | Annotate | Download | only in timing
      1 #include "timing.h"
      2 #include <stdio.h>
      3 
      4 #ifndef LIBNAME
      5 #define LIBNAME UNKNOWN
      6 #endif
      7 
      8 #define LIBSTRING		LIBSTRINGX(LIBNAME)
      9 #define LIBSTRINGX(a)	LIBSTRINGXX(a)
     10 #define LIBSTRINGXX(a)	#a
     11 
     12 double __floatundidf(uint64_t x);
     13 
     14 int main(int argc, char *argv[]) {
     15 #define INPUT_SIZE 512
     16 	uint64_t input[INPUT_SIZE];
     17 	int i, j;
     18 
     19 	srand(42);
     20 
     21 	// Initialize the input array with data of various sizes.
     22 	for (i=0; i<INPUT_SIZE; ++i)
     23 		input[i] = (((uint64_t)rand() << 32) | (uint64_t)rand()) >> (rand() & 63);
     24 
     25 	double bestTime = __builtin_inf();
     26 	void *dummyp;
     27 	for (j=0; j<1024; ++j) {
     28 
     29 		uint64_t startTime = mach_absolute_time();
     30 		for (i=0; i<INPUT_SIZE; ++i)
     31 			__floatundidf(input[i]);
     32 		uint64_t endTime = mach_absolute_time();
     33 
     34 		double thisTime = intervalInCycles(startTime, endTime);
     35 		bestTime = __builtin_fmin(thisTime, bestTime);
     36 
     37 		// Move the stack alignment between trials to eliminate (mostly) aliasing effects
     38 		dummyp = alloca(1);
     39 	}
     40 
     41 	printf("%16s: %f cycles.\n", LIBSTRING, bestTime / (double) INPUT_SIZE);
     42 
     43 	return 0;
     44 }
     45