Aller au contenu | Aller au menu | Rechercher

Blog | Budget | Gallery | Sys Info |

LibCycle - a cycle counter library

About LibCycle

This library helps to estimate number of cpu cycles consumed per function.

Usage

#include 

CYCLE_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

Requirements

This library only need a C compiler to be build.

To install, one only needs to

Changelogs

LibCycle 1.4.0 (Tue, 03 Jun 2014 09:08:07 +0200)

LibCycle 1.2 (Tue, 17 Sep 2013 12:15:50 +0200)

LibCycle 1.0 (Tue, 6 Mar 2012 14:46:55 +2000)

LibCycle 0.1 (Tue, 5 May 2009 19:26:51 +0200)

Page créee/modifié le 20 septembre 2013.

Envoyez tout commentaire à Laurent Mazet

Ce site fonctionne avec des logiciels libres tels que Debian GNU/Linux, Apache, MySQL et PHP

Valid XHTML 1.1 Valid CSS!