int main()
{
time_t inicio;
time_t fim;
int v[5] = {3,4,3,5,4};
int i;
inicio = time(NULL);
for(i=0;i<5;i++)
printf("%d \n",v[i]);
fim = time(NULL);
printf("Tempo = %f \n",difftime(fim, inicio));
system("PAUSE");
return 0;
}
Runtime
Started by Apprentice123, Nov 06 2009 06:13 AM
8 replies to this topic
#1
Posted 06 November 2009 - 06:13 AM
I want to calculate the runtime, but the result is always 0
|
|
|
#2
Posted 06 November 2009 - 08:47 AM
The runtime for that is likely to be measured in thousandths of a second, if that.
#3
Posted 06 November 2009 - 09:00 AM
WingedPanther said:
The runtime for that is likely to be measured in thousandths of a second, if that.
int main()
{
time_t inicio;
time_t fim;
int v[5] = {3,4,3,5,4};
int i;
inicio = time(NULL);
for(i=0;i<5;i++)
printf("%d \n",v[i]);
fim = time(NULL);
[B] printf("Tempo = %f \n",(difftime(fim, inicio))/1000);[/B]
system("PAUSE");
return 0;
}
But the result is 0
#4
Posted 06 November 2009 - 09:26 AM
Even if I convert to thousandths of seconds, seconds or hours the result is 0
#5
Posted 06 November 2009 - 09:26 AM
My guess: difftim(fim, inicio) is less than 1000, so dividing by 1000 results in 0.
#6
Posted 06 November 2009 - 09:29 AM
WingedPanther said:
My guess: difftim(fim, inicio) is less than 1000, so dividing by 1000 results in 0.
If I do not divide is also 0
#7
Posted 06 November 2009 - 11:43 AM
time_t has a limited resolution. Your program may be running too fast for it to measure.
#8
Posted 06 November 2009 - 03:29 PM
WingedPanther said:
time_t has a limited resolution. Your program may be running too fast for it to measure.
How can I increase the limit?
#9
Posted 07 November 2009 - 06:44 AM
The exact definition is implementation defined. That can include limits on the OS.
You can also try using clock_t, clock(), and CLOCKS_PER_SEC.
You can also try using clock_t, clock(), and CLOCKS_PER_SEC.


Sign In
Create Account


Back to top









