assuming precise_clock_t is clock cycle this is what I get from my little test harness with strings no longer than 20 character.
gcc tester.c -o tester
./tester
15576 "conditional strcmp" took : 636044 clock cycles
average time for a single "conditional strcmp": 40 clock cycles
176 "switch" took : 1704 clock cycles
average time for a single "switch": 9 clock cycles
gcc tester.c -o tester -O
./tester
15576 "conditional strcmp" took : 549984 clock cycles
average time for a single "conditional strcmp": 35 clock cycles
176 "switch" took : 504 clock cycles
average time for a single "switch": 2 clock cycles
gcc tester.c -o tester -O2
./tester
15576 "conditional strcmp" took : 469156 clock cycles
average time for a single "conditional strcmp": 30 clock cycles
176 "switch" took : 480 clock cycles
average time for a single "switch": 2 clock cycles
> what's the unit of the precise_clock_t?
I think it's a direct measurement of your processor clock speed.
Simplisticly, it counts the number of instructions executed.
In reality, many instructions take several clock ticks to execute.
But it does mean you can make a direct comparison between two processors, since you should get the same results from the same code running on two different processors which differ only by their clock speed.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.