LibCycle 1.2 發布,估算每個函數消耗的CPU周期數
LibCycle是一個庫,可以幫助估計每個函數消耗的CPU周期數。
int randn ()
{
CYCLE_COUNTER_TIC();
int i = 0;
float x, y;
int r = 0;
for (i = 0; i < 10; i++) {
CYCLE_COUNTER_TIC(intern_while);
do {
x = (float) rand () / ((float)RAND_MAX + 1);
} while (x == 0);
CYCLE_COUNTER_TOC(intern_while);
y = (float) rand () / ((float)RAND_MAX + 1);
float z = sqrtf (-2. * logf (x)) * cosf (2 * M_PI * y);
r = z * (1 << 31);
}
CYCLE_COUNTER_TOC();
return r;
}
int main (int argc, char *argv[])
{
int i;
printf ("random:");
double sum_rd = 0;
for (i = 0; i < N; i++) {
sum_rd += randn ();
}
printf (" done\n");
display_cycle_counters ();
return 0;
}</pre>
發布說明: This release is the first public version. There's also some adaptation for the x64 architecture, and an internal implementation of sqrt to remove a dependency on the math library.
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!