# function time

**URL:** <https://community.unix.com/t/function-time/170998>\
**Category:** Programming\
**Created:** [May 4, 2007, 7:03am UTC](https://community.unix.com/t/function-time/170998 "2007-05-04T07:03:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scotty\_123](https://community.unix.com/letter_avatar/scotty_123/32/5_5575768a8748004e209b776fc1b2916d.png) [@scotty\_123](https://community.unix.com/u/scotty_123)\
**Post date:** [May 4, 2007, 7:03am UTC](https://community.unix.com/t/function-time/170998/1 "2007-05-04T07:03:40Z")

</div>

Hello

I have problem with function 'time' to test my program for file copying .  
How to run the function in my source code ?

I try something like that:

system("time"); \< -- but this don't working

---

<div class="post-metadata">

**Author:** ![ilko\_partizan](https://community.unix.com/user_avatar/community.unix.com/ilko_partizan/32/533_2.png) [@ilko\_partizan](https://community.unix.com/u/ilko_partizan)\
**Post date:** [May 4, 2007, 9:33am UTC](https://community.unix.com/t/function-time/170998/2 "2007-05-04T09:33:28Z")

</div>

You should try with API "times".  
%man 2 times

Best regards,  
Iliyan Varshilov

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [May 4, 2007, 9:51am UTC](https://community.unix.com/t/function-time/170998/3 "2007-05-04T09:51:22Z")

</div>

From the command line:

```nohighlight
time mycopyprog arg1 arg2
real 0m0.03s
user 0m0.01s
sys 0m0.03s

```

reports the wall clock time, and time in kernel and user mode.

Use a profiler

```nohighlight
cc -p -g mycopyprog.c -o mycopyprog
mycopyprog arg1 arg2
prof mycopyprog
... lines of output

```

-- with gcc use the same options, but use grpof instead of prof

Or: call gettimeofday before the copy function is called, and then call it again after.  
Subtract the two timeval structs to get the time.  
man gettimeofday
