Hello, On Tue, 12 Jan 2010, Per Jessen wrote:
David Haller wrote:
On Tue, 12 Jan 2010, Per Jessen wrote: [..]
I'm processing a dataset of 262176 bytes. Not a lot, but still about 2million bits. The computation is 99.9% CPU-bound.
In my first version, I used a div instruction in the code, and the computation took 151minutes (wall-time). In the second, I removed the div, and probably removed one or two other instructions. New computation took 62minutes.
... and replaced it by what? And have you compared to C-Code compiled with gcc or icc? ;)
The div was a divide by 10 followed by examination of remainder and quotient. Under the circumstances, the number being divided would always be in the range 0-19, which meant I could easily substitute with a subtract 10 and a check of the result. The div was effectively replaced by 3 other instructions, and I think I managed to do away with one more instruction along the way. (I really only looked at the timing).
As for gcc code, I did start out with C-code for a quick prototype. I also had a quick look at what was generated - it would have been horrendously slow in comparison. After all, neither gcc nor icc could have been aware of the special circumstances that I knew about. Hand-optimized assembler will _always_ beat the compiler, but the trade-off is in speed vs maintainability. The latter is (in this project) not a concern for me.
Definitely not. Generated code can be surprisingly efficient today (with proper options). But, in special cases, of course, *nothing* beats hand-crafted assembler[1] ;) But one should check that it actually does. I'm glad you found a good solution. Have Fun! -dnh, more of a perlmonger, and I do run benchmarks there, with at times surprising results :) [1] just have a look at my /bin/true ;) 45 Bytes hand- + nasm-crafted bytes of ELF Binary. Not by me, mind you. http://www.muppetlabs.com/%7Ebreadbox/software/tiny/true.asm.txt -- Lies halt mal dclp.*, da faellt dir nix mehr ein. Wenn man ein Guerteltier ueber die Tastatur abrollt, kommt besserer PHP Code raus als da gepostet wird. -- R. Huebenthal in darw -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org