?
Solved

file input output

Posted on 2011-04-21
6
Medium Priority
?
335 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:zizi21
  • 3
  • 3
6 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 35439911
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
 

Author Comment

by:zizi21
ID: 35439944
>>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
 

Author Comment

by:zizi21
ID: 35439958
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Infinity08
ID: 35440028
>> 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
 

Author Comment

by:zizi21
ID: 35440553
Thanks a lot.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 35440806
No problem :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question