Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am on a project and i have to compare some sorting algorithms execution times. However, as you know some values are to close, but i can not see difference. I have to know, small difference for example 1 nanosecond or something.

Is that possible to measure very small difference-smaller then microsecond or something.
Posted
Comments
[no name] 1-Jan-14 8:06am    
Surely you are not trying to measure the speed of one iteration. You do not need nanosecond resolution to measure the speed of algorithms. You measure large numbers of iterations so that a small error in time measurement doesn't matter. This is a very fundamental principle of mensuration.
CPallini 5-Jan-14 15:31pm    
(virtual) 5.
CPallini 5-Jan-14 15:36pm    
As already suggested by pwasser measuring algorithm speed that way doesn't make sense. Moreover usually the interesting feature of an algorithm is its order of growth, see
http://en.wikipedia.org/wiki/Analysis_of_algorithms#Orders_of_growth

I've written a nice high resolution C++ Stopwatch class, located at the bottom of hwindatetime.h[^].

It's easy to use with an interface that should be familiar to many .Net developers.

Best regards
Espen Harlinn
 
Share this answer
 
 
Share this answer
 
Comments
Philippe Mori 1-Jan-14 16:58pm    
Link was already provided in Solution 1...
[no name] 2-Jan-14 7:11am    
Can happen in a parallel envirnoement, while two persons write the answer about the same time ;)
__time_t is defined as __time64_t or __time32_t, for time holder, and the macro is

/* Clock ticks macro - ANSI version */
#define CLOCKS_PER_SEC 1000

so if you want to redefine it in your code
C++
#ifdef CLOCKS_PER_SEC
#undef CLOCKS_PER_SEC
#define CLOCKS_PER_SEC 10000000000000
#else
#define CLOCKS_PER_SEC 10000000000000
#endif
 
Share this answer
 
dear friend
I road somthing about this topic in


www.cs.rpi.edu/~musser/gp/timing.html‏[^]
I hope that it help you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900