About LibCycle
This library helps to estimate number of cpu cycles consumed per function.
Usage
#includeCYCLE_COUNTER_TIC (name); CYCLE_COUNTER_TOC (name); CYCLE_COUNTER_DOWN (name); CYCLE_COUNTER_UP (name); display_cycle_counters ();
Macro CYCLE_COUNTER_TIC() creates a cycle counter. Usually, this macro is inserted at the beginning, just after variable declaration section, of any function one wants to bench. This macro also stores the actual cpu cycle reference; to measure cpu cycle, one needs to 'stop' the running counter with the other macro CYCLE_COUNTER_TOC.
Macro CYCLE_COUNTER_TOC() stops a running counter, increments the counter call number, and store in a global table the difference between the actual cpu cycle reference and the previously stored
Function display_cycle_counters() displays cycle counter statistics depending of value stored in environment variable CYCLE_COUNTERS_. This function is usually called before exiting, at the end of the main function or in a signal handler. If the value of CYCLE_COUNTERS_ is 'y' or any number greater or equal than 1, statistics are shown in columns: total number of cpu cycles, number of calls, rate of cycle per call in cycles, rate in micro-seconds, in parenthesis standard deviation of the rate in micro-seconds, function name or defined label preceded by a semi-column, and last information surround by brackets is the file name of the code. If the rate is lower than 1us, figure of rate in cycle per call is preceded by an exclamation point.
Variable
Variable CYCLE_COUNTERS_ allows to activated cycle counter mechanism. If it contains 'y' or '1', counters will be effective. If it contains any value greater than 1, display_cycle_counter function will also display number of cycles for the last calls.
Examples
The following example shows what is needed to add in all function to be bench.
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; }
Screen-shot
Shell view
Downloads
Source packages
Debian packages
- LibCycle version 1.4.0 (i386)
- LibCycle version 1.4.0 (amd64)
- LibCycle version 1.4.0 (dev i386)
- LibCycle version 1.4.0 (dev amd64)
Requirements
This library only need a C compiler to be build.
To install, one only needs to
- unpack the archive,
- do a 'make',
- and a 'make install'.
Changelogs
LibCycle 1.4.0 (Tue, 03 Jun 2014 09:08:07 +0200)
- Make library thread safe
- Pack cycle counter structure (backward compatibility)
- Split debian packaging
- Better statistic display
- Force semi-colomn after CYCLE_COUNTER_* macros
LibCycle 1.2 (Tue, 17 Sep 2013 12:15:50 +0200)
- - First public version
- - Optimize sqrtf
- - Adapt cycle counters to x64
- - Remove dependency to math library
LibCycle 1.0 (Tue, 6 Mar 2012 14:46:55 +2000)
- - Fix cycle counter when program hang-up
- - Avoid display of non used counter
- - Cycle counter tic and toc have an extra parameter to allow setting multiple counter per function
- - Compute standard deviation for cycle counter
- - New macros to locally deactivate a cycle counter
- - Add an exclamation point on non-measurable functions
LibCycle 0.1 (Tue, 5 May 2009 19:26:51 +0200)
- - Initial version