Ad
  • Default User Avatar

    I'd be extremenly surprised if it's optimized, there's too many things to check for the optimization to be possible.
    Well, I suppose JVM can be a Python runtime too, but I'm not sure if even JVM has come this far.

  • Custom User Avatar

    Depends on the runtime. I would not be surprised if the python runtime optimized our the declaration. Would have to run actual tests to confirm or refute.

  • Default User Avatar

    and it's repeated for each function call too! :D

  • Custom User Avatar

    It should be pointed out that it's only more performant across multiple executions within the same memory space. If all you care about is the runtime of one execution, then pyramidka's is almost twice as fast, even when x is 1.

    >>> factorial.lookup = []
    >>> f1(1)
    5.00679016113e-06
    >>> f2(1)
    9.05990600586e-06
    
    >>> factorial.lookup = []
    >>> f1(15000)
    0.0543911457062
    >>> f2(15000)
    0.101855039597```
    
  • Custom User Avatar

    Slightly inefficient to create the dict for each iteration of the comprehension.