-3

Is there any way when I run time command with option -c on my program it show me 0 secs under user section? Is this what we'd call that the program is not CPU bound? I have a program for which I'm always getting 0.01 secs. I've done some optimizations, but still the same. I've got this program run time from around 8secs down to 0.01 secs but I can't reduce further. Is this something to do with sampling interval in context of activity time capture?

Diwakar Sharma
  • 415
  • 1
  • 9
  • 26

1 Answers1

1

No, "not CPU bound" means that the application's performance is constrained by something else, typically by the amount of I/O it is doing. It does not refer to any specific running time, it just means that the application is sitting waiting for I/O to complete or something most of the time.

Since time, on Linux at least, shows system time as well as user time, and user time is a measure of how much your code is actually running, as opposed to the OS kernel's code, if your user time is much lower than the wall clock time that is crude evidence that your program is "not CPU bound".

It is a strange question. But I guess it does not need answering now that you know that you have misunderstood "not CPU bound".

Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • Ok.. Suppose if I'm reading characters from stdin using getchar(). I don't know how many more characters are yet to arrive. So as per definition of CPU bound , I can't make this scenario non-CPU bound , right? because I'll have to keep looping till EOF. – Diwakar Sharma Nov 09 '13 at 09:34
  • @DiwakarSharma if you are reading from the user it is already non-CPU bound in that part of the program, because you are limited by the speed of the user's typing, not the speed of the CPU. If you might be reading from a file redirected into stdin, you should consider some more efficient block I/O method of reading data from stdin. – Robin Green Nov 09 '13 at 09:37
  • Exactly as you said , I'm redirecting a file to stdin like ./a.out < file – Diwakar Sharma Nov 09 '13 at 09:40
  • OK, then you can use `read` instead of `getchar`, for example. – Robin Green Nov 09 '13 at 09:41