* time system call expensive?
@ 2011-07-21 4:41 Vadiraj
2011-07-21 11:20 ` Michal Nazarewicz
0 siblings, 1 reply; 4+ messages in thread
From: Vadiraj @ 2011-07-21 4:41 UTC (permalink / raw)
To: linux-c-programming
Hi All,
I'm evaluating time consumed by method. I'm using time(NULL) system
call to capture time before and after the call to the function.
Just wanted to know if this has a considerable performance hit? For
all I believe time syscall is quite optimized and should not really be
matter of concern.
Please let me know if someone have evaluated time(NULL) system over head..
Assuming the method I'm evaluating is a frequently called method.
Thanks in advance.
Regards,
Vadi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: time system call expensive?
2011-07-21 4:41 time system call expensive? Vadiraj
@ 2011-07-21 11:20 ` Michal Nazarewicz
2011-07-21 11:46 ` Akos Marton
0 siblings, 1 reply; 4+ messages in thread
From: Michal Nazarewicz @ 2011-07-21 11:20 UTC (permalink / raw)
To: linux-c-programming, Vadiraj
On Thu, 21 Jul 2011 06:41:14 +0200, Vadiraj <vadiraj.cs@gmail.com> wrote:
> I'm evaluating time consumed by method. I'm using time(NULL) system
> call to capture time before and after the call to the function.
> Just wanted to know if this has a considerable performance hit? For
> all I believe time syscall is quite optimized and should not really be
> matter of concern.
>
> Please let me know if someone have evaluated time(NULL) system over
> head..
>
> Assuming the method I'm evaluating is a frequently called method.
Why do you worry about it? What do you need the time for? If are
really using time(2) it means that the function you're calling run time
is counted in seconds. If that's the case, two call to time(2) are
by all means negligible.
If you need in for benchmark, you would probably do something like:
start = time(NULL)
for (vary big number)
call function you benchmark
end = time(NULL)
In either case, you should check gettimeofday(2).
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: time system call expensive?
2011-07-21 11:20 ` Michal Nazarewicz
@ 2011-07-21 11:46 ` Akos Marton
2011-07-22 4:57 ` Vadiraj
0 siblings, 1 reply; 4+ messages in thread
From: Akos Marton @ 2011-07-21 11:46 UTC (permalink / raw)
To: Michal Nazarewicz; +Cc: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1169 bytes --]
I advice you `man 3 clock`.
If you want to get much more precision the attached project can help you.
Does it help?
Regards,
mAkos
Michal Nazarewicz wrote:
> On Thu, 21 Jul 2011 06:41:14 +0200, Vadiraj <vadiraj.cs@gmail.com> wrote:
>> I'm evaluating time consumed by method. I'm using time(NULL) system
>> call to capture time before and after the call to the function.
>> Just wanted to know if this has a considerable performance hit? For
>> all I believe time syscall is quite optimized and should not really be
>> matter of concern.
>>
>> Please let me know if someone have evaluated time(NULL) system over head..
>>
>> Assuming the method I'm evaluating is a frequently called method.
>
> Why do you worry about it? What do you need the time for? If are
> really using time(2) it means that the function you're calling run time
> is counted in seconds. If that's the case, two call to time(2) are
> by all means negligible.
>
> If you need in for benchmark, you would probably do something like:
>
> start = time(NULL)
> for (vary big number)
> call function you benchmark
> end = time(NULL)
>
> In either case, you should check gettimeofday(2).
>
[-- Attachment #2: timing.tar.bz2 --]
[-- Type: application/octet-stream, Size: 1150 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: time system call expensive?
2011-07-21 11:46 ` Akos Marton
@ 2011-07-22 4:57 ` Vadiraj
0 siblings, 0 replies; 4+ messages in thread
From: Vadiraj @ 2011-07-22 4:57 UTC (permalink / raw)
To: linux-c-programming
Great!! thanks for the tar.
I'm not sure if we can time() sys call is quite expensive all time.
Simple code I tried
#include <stdio.h>
#include <time.h>
int main()
{
int i,k = 0;
time_t t,j;
for(i =0 ; i < 100; i++)
{
usleep(100);
//t = time(NULL);
k++;
//j = time(NULL);
}
}
Time without the time() calls.
time ./time_performance
real 0m2.091s
user 0m0.000s
sys 0m0.001s
output with time calls.
time ./time_performance
real 0m2.007s
user 0m0.000s
sys 0m0.001s
Almost same.
timing k++ is not the righ thing but the point is, time as such is not
so expensive IMHO. I did notice considerable difference when I loop to
a 100000 times without the usleep().
just k++ in the loop.
time ./time_performance
real 0m0.003s
user 0m0.000s
sys 0m0.003s
with time() sys call before and after k++ in the loop.
time ./time_performance
real 0m0.168s
user 0m0.026s
sys 0m0.139s
Cheers,
Vadi
On Thu, Jul 21, 2011 at 5:16 PM, Akos Marton <makos999@gmail.com> wrote:
> I advice you `man 3 clock`.
> If you want to get much more precision the attached project can help you.
> Does it help?
>
> Regards,
> mAkos
>
>
> Michal Nazarewicz wrote:
>> On Thu, 21 Jul 2011 06:41:14 +0200, Vadiraj <vadiraj.cs@gmail.com> wrote:
>>> I'm evaluating time consumed by method. I'm using time(NULL) system
>>> call to capture time before and after the call to the function.
>>> Just wanted to know if this has a considerable performance hit? For
>>> all I believe time syscall is quite optimized and should not really be
>>> matter of concern.
>>>
>>> Please let me know if someone have evaluated time(NULL) system over head..
>>>
>>> Assuming the method I'm evaluating is a frequently called method.
>>
>> Why do you worry about it? What do you need the time for? If are
>> really using time(2) it means that the function you're calling run time
>> is counted in seconds. If that's the case, two call to time(2) are
>> by all means negligible.
>>
>> If you need in for benchmark, you would probably do something like:
>>
>> start = time(NULL)
>> for (vary big number)
>> call function you benchmark
>> end = time(NULL)
>>
>> In either case, you should check gettimeofday(2).
>>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-07-22 4:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-21 4:41 time system call expensive? Vadiraj
2011-07-21 11:20 ` Michal Nazarewicz
2011-07-21 11:46 ` Akos Marton
2011-07-22 4:57 ` Vadiraj
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).