in reply to Re^7: Run Perl 5 in the Browser!
in thread Run Perl 5 in the Browser!

This means Perl's op-codes are executed at "native speed". But JS code is normally far better optimized by using JIT. The same algorithm in JS and Perl will normally run (much) faster in JS.

True, with Perl there's the additional layer of the execution of opcodes. I don't know much about JavaScript JIT, but if it's compiling to native machine code (and not something internal like WebAssembly), then yes, the same algorithm in JS should be faster than WebPerl.

Replies are listed 'Best First'.
Re^9: Run Perl 5 in the Browser!
by LanX (Saint) on Aug 22, 2018 at 22:23 UTC
    It's not that much about native code but reducing dynamic typing to the most "probable" static types.

    A scalar in Perl is a container which can be internally an integer or a float, a string, a ref, an object ... etc.

    Very similar in JS.

    Each time you have an operation on two dynamic data types, the VM needs to find out how to combine the cases for the two types.

    But if in the dynamic process you found out that the variables involved "always" (or mostly) have the same type, you can JIT compile to optimized code.

    In other words: The JIT compiler can treat the code as if the variables where statically typed.

    see https://hacks.mozilla.org/2017/02/a-crash-course-in-just-in-time-jit-compilers/ for a nice explanation.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice