[英]How to count time in seconds in Allegro 5
I've got a problem with counting time in Allegro5. 我在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
我必须做一个项目到学校,我将展示shellort,它是如何工作的以及它排序数组的速度有多快而且存在问题
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 当我执行它时它什么也没做,
shellTime
变量是一个int64_t
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. 您可以使用al_get_time以秒为单位获取当前时间,但是allegro定时器仅与底层的os时钟一样准确。
What you really want is a high performance timer for this situation. 您真正想要的是针对这种情况的高性能计时器。 Look at Query performance counter
查看Query性能计数器
on Windows and clock_gettime on Linux 在Windows上和Linux上的clock_gettime
They will give you nanosecond accuracy 它们将为您提供纳秒精度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.