[...]
The only reason I can think of is that it doesn't work in VC++.
It does work in MSVC++, although doing slightly different thing than in
Linux (measuring wall time instead of process cpu time). However, it
seems its behavior varies in different *nix flavors.
The meaning of clock is specified by the C standard: "The
clock() function shall return the implementation's best
approximation to the processor time used by the process since
the beginning of an implementation-defined era related only to
the process invocation." Under Windows, this means that the
return value should be based on the lpUserTime field returned by
GetProcessTimes.
And the only real differences I've encountered in different Unix
variants is the value of CLOCKS_PER_SECOND (and then, only in
legacy Unices---modern Unix requires it to be one million) and
the value returned by the first call to clock().
Maybe the behavior differencies were the reason of the ban? In this case
there are many other functions behaving slightly differently on different
platforms. Printf() rounding rules pop into mind first (not sure if
iostream rounding is also affected or not).
That's basically what I said: the Windows implementation is
broken, and doesn't have standard conformant semantics. It's
not a "slight difference".
Yes, benchmarking is certainly the main use case for clock(). When
benchmarking one should take care anyway that there are no other
significant programs running at the time of tests, and the benchmarked
sections of code typically do not contain any sleeps, so the difference
between Windows/Linux is not so important any more.
On the usual desktop platforms, you cannot prevent other
processes from running. And my experience is that the values
returned under Solaris or Linux are usable; those under Windows,
usually not. (But in all cases, I'm running without admin
rights, and cannot stop background processes; e.g. the
anti-virus kicks in when it wants to, and I cannot turn it off,
even for a second. If you're running on a single user system,
with only a single core, with all services turned off, and no
connection to any network, you might be right.)