12 __int64 cycles
,mint
,maxt
;
18 static void rdtsc(__int64
*t
)
22 QueryPerformanceCounter(&now
);
24 #elif !defined(_WIN32)
25 struct timeval tm
={0,};
26 gettimeofday(&tm
,NULL
);
27 *t
= ((__int64
)tm
.tv_sec
)*1000000 + (__int64
)tm
.tv_usec
;
40 void _timingInit(void)
42 memset(timingInfo
,0,sizeof(timingInfo
));
45 void _timingEnter(int which
)
47 rdtsc(&timingInfo
[which
].st_time
);
50 void _timingLeave(int which
)
54 t
-= timingInfo
[which
].st_time
;
55 if (!timingInfo
[which
].mint
|| t
< timingInfo
[which
].mint
) timingInfo
[which
].mint
=t
?t
:1;
56 if (t
> timingInfo
[which
].maxt
) timingInfo
[which
].maxt
=t
;
57 timingInfo
[which
].cycles
+= t
;
58 timingInfo
[which
].calls
+= 1;
61 void _timingPrint(void)
64 for (x
= 0; x
< sizeof(timingInfo
)/sizeof(timingInfo
[0]); x
++)
67 if (timingInfo
[x
].calls
)
70 sprintf(buf
,"%d: %d calls, %.4f clocks/call (min=%.4f, max=%.4f). %.8f thingies of CPU time spent\n",
71 x
,timingInfo
[x
].calls
,(timingInfo
[x
].cycles
/(double)timingInfo
[x
].calls
),
72 (double)timingInfo
[x
].mint
,(double)timingInfo
[x
].maxt
,
73 (double)timingInfo
[x
].cycles
74 #if defined(_WIN64) || !defined(_WIN32)
77 / (2.4*1000.0*1000.0*1000.0)
82 OutputDebugString(buf
);
89 if (!p
) OutputDebugString("no calls to timing lib\n");
91 if (!p
) printf("no calls to timing lib\n");