On Thu, Sep 16, 2021 at 5:15 AM Mostowski Collapse <burse...@gmail.com> wrote: > > 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. >
No, you're thinking in terms of microoptimizations. Exception handling isn't THAT slow. I'm talking more about how everything's getting packaged up and then unpackaged (the repeated use of the "Compound" class looks highly suboptimal), rather than reworking your algorithm to behave more cleanly. ChrisA -- https://mail.python.org/mailman/listinfo/python-list