> By display, I mean the screen display of the printf took so much addtl. time.
Exactly.
For every line output, it has to scroll the 50-100 lines visible on screen, and maybe 1000's of lines in the history buffer (what scrollback buffer did you set).
1 2
|
$ ./a.out | wc -l
18053368
| |
Considering that your instrumented code outputs over 18 MILLION lines of text, that's a hell of a lot of scrolling!.
You might want to consider targeting your logging at specific areas of interest. You're not going to wade through that volume of output and discover meaning.
Using "
| tail -3" is very efficient, since tail only keeps an internal ring buffer of the 10 most recent lines. It only outputs when it's input is complete (the pipe is closed).
> as compared to the time reported by you for the un-commented version.
Not all machines are equal.
Cygwin is a compatibility layer between the OS your program expects (Linux) and the OS you really have (Windows). What needs to be done to maintain that illusion varies depending on what you're doing, but the cost is never zero.
Besides, my machine will take seconds to run the program if I try to do any work with the 200MB of data the program spews out.
It's only meaningful to get performance data on the version without voluminous printfs, when optimisation is enabled.
1 2
|
$ g++ -O2 sp_nc.cpp -o sp_nc
$ ./sp_nc
| |
> I am unable to find the significance of (lrand48() >> 4) in the statement at line #54
https://en.wikipedia.org/wiki/Linear_congruential_generator
Such generators are notoriously bad random number generators in the least significant bits. Some examples of rand()%2 will produce nothing but 0,1,0,1,0,1,0,1,0,1,0 ....
So >>4 will throw away the bottom 4 bits, presumably with the hope that the resulting pseudo random number is a bit more random and a bit less pseudo.