LibCycle 1.2 发布,估算每个函数消耗的CPU周期数

jopen 11年前

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;  }

LibCycle 1.2 发布,估算每个函数消耗的CPU周期数
发布说明: 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.