Two programs are "equivalent" if and only if given the same input, the
output is the same. That is, what are used in the two programs do not
matter.
Now, given the same input and the same output, theoretically, we can
have a fastest perl program and a fastest C program that are
equivalent. "fastest" is measured in terms of the runtime.
It is generally understand that this fastest perl program is slower
than this fastest C program in a lot of cases. I want to understand
why it is so and what features in perl cause perl be slow in these
cases.
Are you sure it is only the runtime type check make perl slower.
I have no interest in blaming perl is slow. It is not relevant to my
OP to explain in what aspect perl is not slow.
Assembly has operations that can do assignments, addition
substraction, bitwise shifts (multiplication/division), sets
flags, can take the contents of one variable and move it to
another variable. It has hardwired variables and access to
memory locations, which can be variables or hold data.
It has a few real stacks, push/pop etc, and pseudo stacks.
These can all be used to efficiently process data, move it
around, etc..
There is a language below assembly, called microcode. Each assembly
instruction executes several microcode instructions. Below microcode
are flip/flop gates and electron plasma. Below plasma there are quarks
and sub-atomic particles and the quantum physics realm.
This is the language tree up to assembly. Obviously, sub-atomic
particles react faster than assembly instructions. The reason is that
assembly requires organization of the particles into electron gates (cpu),
the gates facilitate microcode, which facilitate assembly.
More and more overhead is required for each level of organization (language)
up you go.
Finally, you reach a point of dynamic language called your desktop, it is
you dragging things around scheduling tasks and doing many things in your
multi-threaded world. You do everyday, dynamically program and run your
own world.
So you see that on the low level, while things are fast, not too much
can be done with limited organization. The more you want done, the more
dynamic an language is, the more organization it takes, the more time
it consumes as with any higher level complexities.
End of PhD thesis!!
-sln