PDA

View Full Version : Is there a high-resolution cross-platform timer in C++'s standard library?



s3a
September 22nd, 2011, 11:54 PM
Is there a high-resolution cross-platform timer in C++'s standard library? I ask because I want to do some benchmarks for an Engineering "English" class (but please don't assume I am too smart since it's my first semester in University and I am not even taking any computer science courses this semester - but I have taken Java courses in the past so I am not clueless). When I Google, I find so many different answers and I'd like to avoid external libraries if possible. I would additionally like to get accuracy down to the nanosecond.

Any help in doing so would be greatly appreciated!
Thanks in advance!

Vaphell
September 23rd, 2011, 02:42 AM
if you couldn't find it then it doesn't exist ;-)

what do you want to measure exactly? nanosecond precision doesn't make much sense either way, measurements will be all over the place, depending on what the machine does at the moment. Usually you get reliable results by repeating measured operation N times (where N is a really big number) and dividing total time by N.

karlson
September 23rd, 2011, 04:12 AM
Is there a high-resolution cross-platform timer in C++'s standard library? I ask because I want to do some benchmarks for an Engineering "English" class (but please don't assume I am too smart since it's my first semester in University and I am not even taking any computer science courses this semester - but I have taken Java courses in the past so I am not clueless). When I Google, I find so many different answers and I'd like to avoid external libraries if possible. I would additionally like to get accuracy down to the nanosecond.

Any help in doing so would be greatly appreciated!
Thanks in advance!

I think you are looking for something like POSIX high-resolution timers. Like timer_create function etc. So I would get something POSIX compliant on "other" platforms you are working on like CYGWIN for Windows.