flat assembler
Message board for the users of flat assembler.
Index
> Windows > Java faster than ASM!? Goto page Previous 1, 2, 3, 4, 5 Next |
Author |
|
revolution 05 Feb 2008, 15:55
If a human is either lazy or does not have the time to think about optimisation then JIT can (in theory) be faster. But for any time critical code it would be folly to just simply leave it up to JIT to optimise it and think it will give beautiful and perfect code, because it won't and it can't. Just the start up overhead means it could never catch a hand-optimised piece of code.
An interesting question is this: Since JIT programs are written by humans can they ever outperform a human at optimisation? |
|||
05 Feb 2008, 15:55 |
|
f0dder 05 Feb 2008, 16:02
revolution wrote: Just the start up overhead means it could never catch a hand-optimised piece of code. Unless you opt for profiled optimization, you only need the startup overhead once, though. And you can optimize for the specific processor the application is installed to... instead of having 32/64bit versions, P4, AM64, core2, ... - but JITs aren't there yet. revolution wrote: An interesting question is this: Since JIT programs are written by humans can they ever outperform a human at optimisation? "It depends" - machines have the advantage that they don't get tired/bored, even when faced with extremely similar & repetitive tasks. So in theory, you could code a "perfect optimizer", which does NP-complete analysis of the problem, something a human would never complete. |
|||
05 Feb 2008, 16:02 |
|
revolution 05 Feb 2008, 16:12
f0dder wrote: ... NP-complete analysis of the problem ... |
|||
05 Feb 2008, 16:12 |
|
drhowarddrfine 05 Feb 2008, 18:50
So this, then, erases any doubt that crept into my mind from my argument with that guy. I've never understood how anyone could claim such a thing since ALL code winds up as asm. It boils down to good code runs faster than not as good code but no higher level language can run faster than asm.
|
|||
05 Feb 2008, 18:50 |
|
rugxulo 05 Feb 2008, 19:36
Just some general comments:
"div" is always slow, use shifts and simple arithmatic instead (if possible). Anyways, I think the smaller the dividend (e.g. AL instead of AX), the faster it'll be. Doesn't "nop" have special hardware circuitry to be fast or is it still slow like the atomic "xchg" (since it's basically same opcode as "xchg ax,ax")? I think Pentium M is just a P3 w/ SSE2 (not a P4), so keep that in mind. Pentium 4 is faster with "add ?,1" instead of "inc". Even GCC generates such (if you tell it to via -march=). |
|||
05 Feb 2008, 19:36 |
|
itsnobody 06 Feb 2008, 00:30
drhowarddrfine wrote: So this, then, erases any doubt that crept into my mind from my argument with that guy. I've never understood how anyone could claim such a thing since ALL code winds up as asm. It boils down to good code runs faster than not as good code but no higher level language can run faster than asm. Not really Java is still faster, using JIT and some better memory management when you add the div instructions Or perhaps the Java runtimes are tweaked specifically for hardware |
|||
06 Feb 2008, 00:30 |
|
LocoDelAssembly 06 Feb 2008, 00:46
Can you show the loop where you are using division in both languages?
|
|||
06 Feb 2008, 00:46 |
|
drhowarddrfine 06 Feb 2008, 03:13
itsnobody wrote:
|
|||
06 Feb 2008, 03:13 |
|
itsnobody 06 Feb 2008, 04:00
drhowarddrfine wrote:
Well I don't know how Java is so fast, ASM is definitely faster in theory As for the instruction I added in it was: Code: mov eax,ecx mov ebx,7 div ebx Which in Java was: Code: nop = count/7; I don't know why the ASM version goes so much slower, the Java version is around 2400 milliseconds while the ASM version is around 2700-2800 milliseconds |
|||
06 Feb 2008, 04:00 |
|
LocoDelAssembly 06 Feb 2008, 04:05
Please, FULL code, it is important what is around. Also, your division code seems to not clear EDX, so you are actually doing a messy division.
|
|||
06 Feb 2008, 04:05 |
|
revolution 06 Feb 2008, 04:08
Your div code should be:
Code: mov eax,ecx xor edx,edx mov ebx,7 div ebx |
|||
06 Feb 2008, 04:08 |
|
itsnobody 06 Feb 2008, 04:20
LocoDelAssembly wrote: Please, FULL code, it is important what is around. Also, your division code seems to not clear EDX, so you are actually doing a messy division. Yes that's right, after adding xor edx, edx it reduced down to 2449 milliseconds...though still slightly slower than Java by 20 milliseconds or so... Ok, here's the full code: Code: include 'win32ax.inc' .data start_time dd 0 _output rb 20 .code start: invoke MessageBox,NULL,"Click Ok to start","Speed Test",MB_OK invoke GetTickCount mov [start_time],eax mov ecx, 100000000 place: mov eax,ecx mov ebx,7 xor edx,edx div ebx dec ecx jnz place invoke GetTickCount sub eax, [start_time] invoke wsprintf,_output,"%d milliseconds",eax invoke MessageBox,NULL,_output,"Speed Test",MB_OK invoke ExitProcess,0 .end start |
|||
06 Feb 2008, 04:20 |
|
LocoDelAssembly 06 Feb 2008, 04:26
Code: mov ebx,7 align 16 place: mov eax,ecx xor edx,edx div ebx dec ecx jnz place Seems to give another little speed up. And still, you could change the DIV by a MUL using the reciprocal trick since 7 is an odd number. It is also possible for even divisors but normally doesn't work for any dividend. |
|||
06 Feb 2008, 04:26 |
|
revolution 06 Feb 2008, 04:28
Don't forget to align the loop to 16.
Code: ... mov ecx,1000000000 mov ebx,7 align 16 place: ... |
|||
06 Feb 2008, 04:28 |
|
LocoDelAssembly 06 Feb 2008, 04:34
http://board.flatassembler.net/topic.php?p=39254#39254 <- Link about division, take special attention to the link posted by Tomasz Grysztar
|
|||
06 Feb 2008, 04:34 |
|
itsnobody 06 Feb 2008, 04:38
LocoDelAssembly wrote:
It doesn't seem to speed things up much Still even with all this optimization, I get it equal to Java, no time ever came up to be faster than Java...all this shows is that some how Java is as fast as ASM |
|||
06 Feb 2008, 04:38 |
|
revolution 06 Feb 2008, 04:47
itsnobody wrote: Still even with all this optimization, I get it equal to Java, no time ever came up to be faster than Java...all this shows is that some how Java is as fast as ASM |
|||
06 Feb 2008, 04:47 |
|
LocoDelAssembly 06 Feb 2008, 04:51
For certain code both will equally faster, that can happens, what cannot however is that assembly is slower that Java, if such thing happens that means just that Java found better CPU instruction sequence than you which means then that you have lower skills than a HLL compiler.
|
|||
06 Feb 2008, 04:51 |
|
itsnobody 06 Feb 2008, 04:51
revolution wrote:
Nah Java is still slower for loading up and graphics, but JIT must be amazing |
|||
06 Feb 2008, 04:51 |
|
Goto page Previous 1, 2, 3, 4, 5 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.