Re: Which is faster?
On Jul 22, 4:42 pm, tni <nob...@example.com> wrote:
James Kanze wrote:
On Jul 21, 12:36 pm, tni <nob...@example.com> wrote:
Windows console output is extremely slow.
And how does that relate to clock()? The standard says that
"The clock function returns the implementation's best
approximation to the processor time used by the program
since the beginning of an implementation-defined era related
only to the program invocation." There are, of course,
enough weasel words in there to make just about anything
formally conform, but the intent is clear that it should be
related to the CPU time used by the program (not the
system), insofar as such is available.
My interpretation of the weasel words is that it's very
reasonable to include system time.
It's debatable. Is the system part of the program, or not. My
first interpretation would be that it isn't, but the point can
easily be argued both ways.
What is clear is that it shouldn't return elapsed time unless no
better alternatives exist (e.g under MS-DOS).
> Console output under Linux isn't particularly fast
either,
Well, Linux (terminal is KDE Konsole 4.2.2) is faster than
Windows by a factor of 150. I would call that fast.
I've not measured the actual difference, but Linux terminal
output is visibly slower than output to /dev/null, or even
output to a remote file. I would call that slow.
but it's system time, not charged to the program, and it
doesn't show up in clock().
Nope. System time is certainly included in the clock() value
on my Linux systems.
I only tried it on one Linux system; the time from clock() was
the same whether the output whent to the terminal, or to
/dev/null.
Come to think of it, however, I don't think that the time used
drawing the characters in the terminal window is "system" time,
either; I'm pretty sure that it is charged to the X server,
which is a separate process. (Time management on Unix systems
is very, very primitive.)
Windows (per 'GetProcessTimes()'; clock() reports real time):
Real time: 19500 ns/char
User time: 2100 ns/char
System time: 2750 ns/char
User+sys time: 4850 ns/char
Linux (per 'time'; clock() reports user + system time):
Real time: 117 ns/char
User time: 11.3 ns/char
System time: 19.7 ns/char
User+sys time: 31 ns/char
(ns as in nano seconds; 1 ns = 3 clock cycles on this CPU)
So any issue with clock() reporting real time on Windows is
WAY smaller than the difference in console output performance
vs. Linux.
I'm afraid I don't understand that sentence.
When redirecting the output to a file, Linux is about 4x
faster; the writes are completely cached, user+sys time is
approximately equal to real time on both.
It depends on how much you're writing. There's a distinct point
where the caching stops working, and the elapsed time makes a
jump.
Of course, in most real applications, you'll be synchronizing
the important writes anyway, to avoid the caching. (In my work,
about the only non-synchronized writes are logging output. And
that very quickly becomes large enough that caching stops
working as well.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34