ANN: Dogelog Runtime, Prolog to the Moon (2021)

alister alister.ware at ntlworld.com
Wed Sep 15 14:17:03 EDT 2021


On Wed, 15 Sep 2021 18:23:10 +0200, Mostowski Collapse wrote:

> I really wonder why my Python implementation is a factor 40 slower than
> my JavaScript implementation.
> Structurally its the same code.
> 
> You can check yourself:
> 
> Python Version:
> https://github.com/jburse/dogelog-moon/blob/main/devel/runtimepy/
machine.py
> 
> JavaScript Version:
> https://github.com/jburse/dogelog-moon/blob/main/devel/runtime/
machine.js
> 
> Its the same while, if-then-else, etc.. its the same classes Variable,
> Compound etc.. Maybe I could speed it up by some details. For example to
> create an array of length n, I use in Python:
> 
>    temp = [NotImplemented] * code[pos]
>    pos += 1
> 
> Whereas in JavaScript I use, also in exec_build2():
> 
>    temp = new Array(code[pos++]);
> 
> So I hear Guido doesn't like ++. So in Python I use +=
> and a separate statement as a workaround. But otherwise,
> what about the creation of an array,
> 
> is the the idiom [_] * _ slow? I am assuming its compiled away. Or does
> it really first create an array of size 1 and then enlarge it?
> 
> Julio Di Egidio wrote:
<sniped due to top posting>

this is probably a string contender

            i = 0
            while i < len(term.args) - 1:
                mark_term(term.args[i])
                i += 1
            term = term.args[i]

try replacing with something more pythonic

for index,term in enumerate(term.args):
     mark_term(term.args[i])


& possibly go all the way to changing it into a comprehension

there are other similar anti patterns throughout this code.

any time you are manually keeping a counter as an index into a list,tupple 
other iterable YOU ARE DOING IT WRONG!

Do not write javascript in python, write python



-- 
Two percent of zero is almost nothing.




-- 
Whoever dies with the most toys wins.


More information about the Python-list mailing list