in reply to Why is this code so much slower than the same algorithm in C?
Let's look at what is really going on when these programs run.
So, whatever terms suits you, which may include one of the following: <opcodes|bytecode|syntax tree|abstract syntax tree|other>.
(Dodge issue!) This is the output from perl -MO=Concise YourScript.pl:
And within that, there is one line: o <2> modulo[t5] sKP/2 ->p
which is the equivalent of these four assembly instructions from the C version:
; Line 8 mov eax, DWORD PTR _i$[ebp] cdq idiv DWORD PTR _j$[ebp] test edx, edx
Now let's look at the assembler that sits behind that perl modulo instruction:
So the answer to your question is: when you understand why those four instructions in the C version, require those 700+ lines of assembler for the perl version, then you'll understand why the performance difference exists.
And also why it isn't a problem!
|
|---|