Ubuntu Pastebin

Paste from sergiusens at Fri, 4 Dec 2015 00:13:16 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
In [76]: print(getattrs); timeit.timeit(getattrs)
class A:
  def a(self):
    pass
  def b(self):
    pass
  def c(self):
    pass
  def d(self):
    pass



a = A()
for step in ['a', 'b', 'c', 'd']:
  getattr(a, step)()

Out[76]: 9.124794365998241

In [77]: print(ifelse); timeit.timeit(ifelse)
class A:
  def a(self):
    pass
  def b(self):
    pass
  def c(self):
    pass
  def d(self):
    pass



a = A()
for step in ['a', 'b', 'c', 'd']:
  if step == 'a':
    a.a()
  elif step == 'b':
    a.b()
  elif step == 'c':
    a.c()
  elif step == 'd':
    a.d()

Out[77]: 9.146868830008316
Download as text