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

Mostowski Collapse bursejan at gmail.com
Wed Sep 15 14:13:23 EDT 2021


If you find a "wonky" spot, I can replace it by "non-wonky"
code. I noticed some differences between Python Dicts
and JavaScript objects. Python tends to throw more exceptions.

So in Python I now do the following:

   peek = kb.get(functor, NotImplemented)
   if peek is not NotImplemented:
                    
In JavaScript I can directly do:

    peek = kb[functor];
    if (peek !== undefined)

But if get() in Python is implemented under the hood with
exception handling. i.e. using the exception prone [] and
then in case an exception is thrown, returning the

default value, then Python get() will probably be quite slow.
Since usually exceptions are slow.

Chris Angelico schrieb am Mittwoch, 15. September 2021 um 19:27:13 UTC+2:
> On Thu, Sep 16, 2021 at 3:17 AM Mostowski Collapse <janb... at fastmail.fm> wrote: 
> > 
> > I really wonder why my Python implementation 
> > is a factor 40 slower than my JavaScript implementation. 
> > Structurally its the same code. 
> >
> Very hard to know. Your code is detailed and complicated. Do they 
> produce identical results? Are you using the same sort of 
> floating-point data everywhere, or is one integer and the other float? 
> What's going on with all the globals, the continuations, etc? My 
> suspicion is that you're trying to write weird, wonky Python code, and 
> then are surprised that it doesn't perform well. 
> 
> ChrisA


More information about the Python-list mailing list