I accidentally noticed that a simple program that creates a class from a large data file works much faster in Python 2.7 compared to 3.5. I read here that using “infinite precision” integers is to blame for the slowdown in a simple enumeration, but even when I tried a simple test that instantiates this class, I found that Python 3 was significantly slower:
class Benchmark(object): def __init__(self): self.members = ['a', 'b', 'c', 'd'] def test(): test = Benchmark() if __name__ == '__main__': import timeit print(timeit.timeit("test()", setup="from __main__ import test"))
I thought that maybe this was due to the size of each instance of the class, but the Python 3 instance was smaller than 2 (56 vs. 64).
$python3 benchmarks.py 0.7017288669958361 $python benchmarks.py 0.508942842484
I tried many variations of this topic, including with 3.4 on another machine, and still get the same results. Any ideas what is going on?
source share