Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perfomance question: strcmp

Status
Not open for further replies.

fl0ra

MIS
Jul 27, 2004
93
0
0
FR
Ok...
I've a quick performance question:

how many clock cycle are required on a P4 to run a strcmp
between to char * 0xFF caracters long.

also
how many clock cycle are required to compute an (int == int) comparison.

Cheers
 
Well I showed you a fast clock Here
Why not write some test code yourself to try it out.

Besides, your processor clock speed is unlikely to be the same as mine.

--
 
ok I'll do that and let you all know the outcome :D
stay tuned in...
 
hmmm btw what's the unit of the precise_clock_t?
 
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.



--
 
Try looking up "Zen Timer" and "Abrash". Huge amounts of info about this and string-comparison. Also "Boyer Moore" and such-like.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top