Assembler speed

Everything todo with programming goes HERE.
Post Reply
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Assembler speed

Post by Jonathan »

I made 6 functions which mirror bits in a 32-bit value and loop 200 million times in C and PPC assembler. Both functions in a C/asm pair perform the same calculations. Results:

Code: Select all

0: 5120070 µs 4286830544
1: 2460696 µs 4286830544
2: 2965320 µs 4286830544
3: 1971526 µs 4286830544
4: 2048973 µs 4286830544
5: 1637023 µs 4286830544
even=C odd=asm: microseconds µs return value

What do you think about it?
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

So, each of the six functions performs the same operation? And each C/ASM pair uses a different approach? And you put the same amount of effort into each function?
If that's the case, than it shows that a well written C function can be faster than a badly written assembler function :) (4 compared to 1) Independently of that, it shows that bit wrangling is clearly a domain where assembler code can shine, although the best ASM to best C comparison only gives a 20% speedup.
User avatar
Jonathan
A Brave Victim
Posts: 3391
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

It also shows that:
- 1 is over twice as fast as 0, so the compiler is not that smart sometimes. The same trick can't be used as much in 2 and 4, which is why 3 and 5 are relatively slow.
- 4 is 3 times faster than 0.
- 5 is 1.5 times faster than 1.

I put about the same amount of effort into C and asm.
Post Reply