0

I've got a problem with counting time in Allegro5. I have to do project to school where I'll show shellsort, how it works and how fast it sort array and there is a problem

I dunno how to count time in seconds, I did some code like this but wont work

ALLEGRO_TIMER *shellTimer = al_create_timer(1.0);
al_start_timer(shellTimer);

// ALGORYTM SHELLA
while (distance) {
    shellCounter++;
    for (int j = NUMBER_OF_ELEMENTS - distance - 1; j >= 0; j--) {
        pos = array[j];
        i = j + distance;
        shellCounter += 2;
        while ((i < NUMBER_OF_ELEMENTS) && (pos > array[i])) {
            array[i - distance] = array[i];
            i += distance;
            counter += 2;
        }
        array[i - distance] = pos;
        shellCounter++;
    }
    distance /= 3;
    shellCounter++;
}

shellTime = al_get_timer_count(shellTimer);
al_stop_timer(shellTimer);

It does nothing when I execute it, the shellTime variable is an int64_t

Swordfish
  • 12,971
  • 3
  • 21
  • 43
Reedy
  • 3
  • 3

1 Answers1

0

You can use al_get_time to get the current time in seconds, but allegro timers are only as accurate as the underlying os clocks are.

What you really want is a high performance timer for this situation. Look at Query performance counter

on Windows and clock_gettime on Linux

They will give you nanosecond accuracy

BugSquasher
  • 335
  • 1
  • 13