タグ

ブックマーク / qiita.com/nubata (1)

  • Pythonのクラスは遅い - Qiita

    import collections import random import time # # クラスで実装。 # class EClass: def __init__(self, x, y): self.x = x self.y = y def test_class(n): l = [] t1 = time.time() for _ in range(n): x = random.random() y = random.random() e = EClass(x, y) l.append(e) t2 = time.time() for e in l: x = e.x y = e.y z = x + y t3 = time.time() return (t1, t2, t3) # # クラス(スロットあり)で実装。 # class EClassSlot: __slots__ = ["x"

    Pythonのクラスは遅い - Qiita
  • 1