in reply to "Get the Job Done" (GeJDo)
in thread Too Many Ways To Do It

The best language when it comes to CPU and RAM usage is machine language. You cannot do better than machine language. At all. No way. The best compiler will only match the machine language implementation, and usually not even come close.

there's actually a lot of debate about this point. unless you're a really, really good assembly programmer, a mature compiler working with well written high-level code will most likely produce faster, more efficient assembly than you can. a good compiler benefits from the years of knowledge and experience of its authors. this means that it knows every trick that they know. it knows the chip inside and out and can make much more sophisticated counter-intuitive optimizations around obscure side-effects of infrequently used instructions. compilers have less of an advantage on RISC architectures than they do on more advanced chips with hundreds of instructions; many more than most humans can hope to fully understand.

of course, if you write bad high-level code, the compiler will happily produce bad assembly code.

and assembly still can't be beat for code size. that and its direct access to the hardware are the reasons people still do use it.

its fun though and will teach you a great deal about computers that you just won't learn from coding high-level languages. you haven't lived till you've spent over 24 hours straight debugging Z-80 assembly.

anyway, i agree with your message though. TIMTOWTDI applies outside perl too. sometimes one of the ways to do it is a different language.

anders pearson

Replies are listed 'Best First'.
Re: Re: "Get the Job Done" (GeJDo)
by John M. Dlugosz (Monsignor) on Sep 20, 2001 at 02:18 UTC
    The last time I used assembly language was a one-line inline asm opcode to call the RDTSC instruction on X86.

    The last significant amount of asm I wrote was a function to convert UTF-16 to UTF-8. I was inspired by a comment in the reference implementation saying "I wish there was a better way to do this" where there is a bunch of if/else chains to test how many leading 1 bits are in a byte. Well, the CPU has an instruction for that. Then, it proved easier just to write it all in asm than to interface a helper function. After all, its work is to push bits around, something asm is good at.

    So, instructions that are not modeled in your high-level language is a good reason to dig to asm.

    —John