looking under the hood of your programs, literally!

it’s common knowledge that high programming languages are different from one another. some are object-oriented while others require VMs. one way these languages differ is how “low” a particular language is to assembly. for those of you who don’t know what assembly is, i’ll put it this way: if you want fast software, you won’t find anything better then assembly. the general rule is that the closer a language is to assembly, the faster it’ll run.

Now, after this nice intro, i’ll get down to business. take a look at the overly simple-code bellow:

int main(){
        int i = 0;
        i+=1;
        return i;
}

you won’t find anything special other than the fact that the a preschooler could have written it. the real fun starts next: assuming you have gcc and gdb, go ahead and compile the source. then start the gdb:

gcc code.c -o code.bin
gdb code.bin

for the other 90% (windows users) : as far as i know, gcc is included with bloodshed dev-C++, the question is whether gdb is included or not. if anyone knows anything, leave a comment.

once running gdb, simply type disas main, and the compiled code will be shown in assembly:

(gdb) disas main
Dump of assembler code for function main:
0x0000000000400448 :	push   %rbp
0x0000000000400449 :	mov    %rsp,%rbp
0x000000000040044c :	movl   $0x0,-0x4(%rbp)
0x0000000000400453 :	addl   $0x1,-0x4(%rbp)
0x0000000000400457 :	mov    -0x4(%rbp),%eax
0x000000000040045a :	leaveq 
0x000000000040045b :	retq   
End of assembler dump.

If anything, this proves that c is fast. but more importantly, it shows how the program is compiled, and therefore, can be compared with other compilable languages to reliably determine execution speed instead of relying on unreliable benchmarking tools.

by the way, i stumbled on this little gem by accident, and I’m glad that i did. now i have proof that C rules 🙂

SIGTERMer

7 thoughts on “looking under the hood of your programs, literally!

  1. I’m guessing you’re using java because it’s cross-platform, but there are other cross-platform languages you can work with like python. java requires a whole VM (or a special chip) just to run, aside its memory issues, and its prerequisites.

    Loolykinns and I rarely agree on anything, but i’m with him on this one. java just has too many issues. but hay, use what works man.

  2. *was*

    not anymore. why, you ask?
    1) retarded (restrictive) memory management.
    2) vm based. not only do i need a jre to run my app. but i still won’t get full OS features unless i go through endless mazes of wrapper functions.

    c is much faster, powerful, simpler, and has far more native control over hardware (via system api).

    but as i said before, if the guy’s ok with it, it’s none of my business.

    btw, nice to see that you haven’t lost your amazing bias against java 😉

  3. Sorry for the late response
    I know that Java has a very restrictive memory management and VM based but
    restrictive management gives Java reliability
    VM gives Java the portability or code once and run in all systems
    And I also know that Java consumes CPU cycles much more than many languages but in business we don’t care about that. All what business want is that work in a reliable manner and that’s what Java can give you

    It’s dying…. yes….. but Java is not dead yet and it is used in Many companies like IBM and Oracle. Even if it died but the concept still exist. You can see that in Android OS.

    And regarding to Python, this language is the future.

  4. like you said, python is the future of cross-platform software development.

    java will probably be replaced by python, and that will be the end of it. the only downside (if you’re a closed source developer) is that it’s a scripting language, hence, anyone is able to view the source.
    and because it’s a scripting language, it’s inherently slower. as you implied, it’s fast enough for most applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.