Re: time system call expensive?

"Michal Nazarewicz" <[email protected]> Thu, 21 Jul 2011 13:20:18 +0200
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <op.vyyu34nf3l0zgt@mnazarewicz-glaptop>
On Thu, 21 Jul 2011 06:41:14 +0200, Vadiraj <[email protected]> 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: [email protected]>-----ooO--(_)--Ooo--