#error Please comment out the next two lines under linux, then comment this error #include "stdafx.h" //Visual studio expects this line to be the first one, comment out if different compiler #include // Include if under windows #ifndef WIN32 #include #endif #include #include #include "rdtsc.h" #include #define NUM_RUNS 1000 int m, n, k; double *A, *B, *C; void compute() { int i,j,h; for(i = 0; i < m; ++i) { for(j = 0; j < n; ++j) { double out = 0; for(h = 0; h < k; ++h) { out = out + A[i*k+h] * B[h*n+j]; } C[i*n+j] += out; } } } double rdtsc() { int i; tsc_counter a, b; /* CPUID instruction serializes the pipeline */ /* Therefore, splits the code to be timed from the code running before */ CPUID(); RDTSC(a); CPUID(); RDTSC(b); CPUID(); RDTSC(a); CPUID(); RDTSC(b); RDTSC(a); for(i=0; i \n"); return -1;} m = atoi(argv[1]); k = atoi(argv[2]); n = atoi(argv[3]); printf("m=%d k=%d n=%d\n",m,k,n); A = (double*)malloc(m*k*sizeof(double)); B = (double*)malloc(k*n*sizeof(double)); C = (double*)malloc(m*n*sizeof(double)); for(i =0; i %lf seconds, assuming frequency is %lf MHz. (change in file if different)\n\n", r, r/(FREQUENCY), (FREQUENCY)/1e6); double c = c_clock(); printf("C clock() function :\n %lf clock ticks measured. On some systems, this number seems to be actually computed from a timer in seconds then transformed into clock ticks using the variable CLOCKS_PER_SEC. Unfortunately, it appears that CLOCKS_PER_SEC is sometimes improperly. (According to this variable, your computer should be running at %lf MHz). In any case, dividing by this value should give a correct timing: %lf seconds. \n\n",c, (double) CLOCKS_PER_SEC/1e6, c/ CLOCKS_PER_SEC); #ifndef WIN32 double t = timeofday(); printf("C gettimeofday() function:\n %lf seconds measured\n\n",t); #else double t = gettickcount(); printf("Windows getTickCount() function:\n %lf milliseconds measured\n\n",t); __int64 f; QueryPerformanceFrequency((LARGE_INTEGER *)&f); double p = queryperfcounter(); printf("Windows QueryPerformanceCounter() function:\n %lf clock ticks measured => %lf seconds, with reported CPU frequency %lf MHz\n\n",p,p/f,(double)f); #endif printf("Type anything to leave\n"); scanf("%d",&i); return 0; }