我想測量一下insert_sort函數的消逝時間。但是,結果是0.0000000秒。我能做什麼?我試過其他時間的圖書館。不幸的是,它沒有......謝謝。我再次寫了。C - 測量功能時間執行
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int number=1;
if(number == 1)
{
struct timeval start, end;
gettimeofday(&start, NULL);
for(int i=0; i<5;i++)
{
insertion_sort(kelime, n);
}
gettimeofday(&end, NULL);
printf("Elapsed time is %.10f",(end.tv_sec * 1000000 + end.tv_usec)- (start.tv_sec * 1000000 + start.tv_usec));
}
看看'rdtsc'內在。 –