Compiler efficiency?

ponder

Honorary Master
Joined
Jan 22, 2005
Messages
98,646
Reaction score
31,306
Location
Niflheimr
How efficient are modern compilers?

Lets say you compile some C code and then look at the assembly equivalent how would it fare?

Why do I ask? I played with Kolibri OS yesterday and it's amazing what the guys achieved in a 4.8MB ISO using assembler :eek:
 
Last edited:
Compilers can often optimize code over larger areas, so the results are sometimes faster than assembler code. However, the main benefit of compilers are in terms of development productivity. Writing a modern application in assembler would usually be way too expensive in terms of developer time for it to be feasible. By the time the assembler based application is finished, the business needs would have changed so much that the application is likely not very relevant any more.
 
Assembler is hardcore. I think it's the second lowest level language you can get, the first being machine code.

As gkm said, compilers can look at the 'bigger picture' and optimize for the entire program flow. This would be very hard to do yourself (but not impossible!) in ASM.

ASM Advantages:

100% Fat-Free - only code what you need
Very Fast - because you only code what you need and the language grants you more freedom in optimizing
Lower Binary Size - as above
Awesome on platforms with memory and processing constraints

ASM Disadvantages:

Not feasible for large applications
More complex due to low level nature
Platform (CPU) dependent - harder to port to different devices
Hard To Maintain (in terms of time needed to code functionality/fixes/etc...)

Game engines for example, mostly use C++ today. Only certain parts of the code are written in assembly and that is usually where bottlenecks would be or a great performance benefit would be obtained.

Today's compilers do a great job (and they're getting better all the time). They can even use the CPU's enhanced instruction sets (SSE, SSE2, MMX, etc...) to squeeze even more performance out of your code. The Intel C++ compiler is great at doing this. It will even try and parallel execute your code for you in loops and such.

If you wrote something in ASM (and you were good at optimizing / taking advantage of a platform's special instruction set) you would be able to beat it though.

The question is, why would you want to? You could put that time in to implementing features or working on a better design. When you do find a performance bottleneck that you cant get around then maybe ASM would be the answer...but then you would need to ask yourself why that's happening. Is it your design? Is it the hardware constraints? Is it the program requirements? Mmmm...

Much to ponder!
 
Last edited:
I'm aware of the advantages/disadvantages. I was just wondering how efficient things have become as things seem pretty big and bloated these days.
 
I think it really depends on the application and the code. For some things, a compiler will produce really good code. For others, I'm sure it would produce lousy code. But definitely good enough for 99% of purposes.
 
Im not that expirienced in Hardware APIs. but from my expirience most of them are written in ASM, i could be wrong though
 
I'm aware of the advantages/disadvantages. I was just wondering how efficient things have become as things seem pretty big and bloated these days.
Things are big and bloated due to Microsoft and their C# and .net rubbish and all this bling-bling they bring (which could have been done in C++ anyhow, but gotta make it easy for the mediocre programmers to be employed you see)

Plain C compilers are now at a level where it doesn't make any realistic sense to code in ASM anymore.
 
Plain C compilers are now at a level where it doesn't make any realistic sense to code in ASM anymore.

+1

even if youre coding an embedded realtime system which runs at a couple of 100 Mhz's youre ok with c compiled asm
 
Plain C compilers are now at a level where it doesn't make any realistic sense to code in ASM anymore.
Yep, agreed.

We've come a long way. It's rare that straight ASM would outperform C, especially if you use a compiler like GCC and MS Visual C++ compiler (with all the optimization settings set to the best mode).

But I can think of a few situations where ASM is still quicker:
- Bit level operations on large integers/floats (eg. encryption), mostly because working with individual bits in C isn't really all that easy.
- Situations where you can work directly with CPU registers where C would place variables on the stack first (incredibly rare that a program would need that kind of performance)

There are definitely more but I can't think of any just now (although I know there are some other scenarios that I've forgotten).
 
ASM has mainly become an embedded system exclusive. Writing in ASM for modern desktop or other form of computer is rather tedious. I agree that desktop compilers have become more bulky. Java in general, when compared to C or ASM has a massive overhead. Garbage collector bleh!

On a processor were there are no advanced mechanisms ASM will outperform almost any other compiled code.
 
ASM has mainly become an embedded system exclusive. Writing in ASM for modern desktop or other form of computer is rather tedious. I agree that desktop compilers have become more bulky. Java in general, when compared to C or ASM has a massive overhead. Garbage collector bleh!

On a processor were there are no advanced mechanisms ASM will outperform almost any other compiled code.

LOL!

Not really, compilers can optimize beyond human capabilities in most cases. Certain sections of code, sure, when you spend lots of time and money developing it.

As for Java, the JVM can outperform both C and C++ in certain operations, primarily because of the garbage collector. Admittedly it has large memory overhead.
 
Top
Sign up to the MyBroadband newsletter
X