• C

file input output

hi,

i have program that uses a lot of file open/close/read/write. the timer says the program took about 10 minutes, but in reality it took 4 hours. why isn't the time taken for the file input and output taken into consideration ?

For the timer, i have used this:
 struct rusage usage;
    getrusage (RUSAGE_SELF, &usage);
   
tq
zizi21Asked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
I assume you used the ru_utime and/or ru_stime members of the rusage struct ?

Those only give you the time that was actually spent on the CPU - performing instructions.

When doing file I/O, a lot of the time will be spent just waiting for I/O (ie. not doing anything).

If you want the wall clock time that expired, you can simply measure that.
0
 
zizi21Author Commented:
>>When doing file I/O, a lot of the time will be spent just waiting for I/O (ie. not doing anything).
I don't understand. why do you wait for i/o and do nothing. i mean, the file pointer would be used to process other things on the file.

>>If you want the wall clock time that expired, you can simply measure that.
is there a C function that measures the clock time. i read and there is example of using the clock
0
 
zizi21Author Commented:
it says the unix time measure the kernel time as well but it specifies the cpu time, does it measure the i/o time.
http://en.wikipedia.org/wiki/Time_%28Unix%29
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
Infinity08Commented:
>> I don't understand. why do you wait for i/o and do nothing.

If your code is making a request to read some data from a file, then that data needs to be retrieved from the disk, copied in memory, and then you can start using that data in memory.
The thing is that reading from disk is VERY slow compared to performing calculations on the CPU, so the CPU has to wait for a (relatively) long time (doing nothing for your thread during that time) until it can continue with the code.

>> i mean, the file pointer would be used to process other things on the file.

I'm not sure what you mean here ...


>> is there a C function that measures the clock time. i read and there is example of using the clock

Sure. There's the standard 'time' function eg. :

        http://www.cplusplus.com/reference/clibrary/ctime/time/

And there are plenty of platform dependent methods of getting the wall clock time.


>> it says the unix time measure the kernel time as well but it specifies the cpu time, does it measure the i/o time.

The time that your code spends performing instructions is referred to as the user time.
The time that your code spends performing system calls is referred to as the system time.
The time that your code spends waiting for I/O is referred to as the iowait time.
0
 
zizi21Author Commented:
Thanks a lot.
0
 
Infinity08Commented:
No problem :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.