fork(1) download
  1. import time
  2.  
  3.  
  4. class DD(object):
  5.  
  6. def __init__(self):
  7.  
  8. self.d = {'pos x':22,'pos y':15,'anchor x':1,'anchor y':33}
  9.  
  10. def doit(self):
  11.  
  12. x = self.d['pos x']+self.d['anchor x']
  13. y = self.d['pos y']+self.d['anchor y']
  14.  
  15.  
  16. class D(object):
  17.  
  18. def __init__(self):
  19.  
  20. self.pos = {'x':22,'y':15}
  21. self.anchor = {'x':1,'y':33}
  22.  
  23. def doit(self):
  24.  
  25. x = self.pos['x']+self.anchor['x']
  26. y = self.pos['y']+self.anchor['y']
  27.  
  28.  
  29. class LL(object):
  30.  
  31. def __init__(self):
  32.  
  33. self.l = [22,15,1,33]
  34.  
  35. def doit(self):
  36.  
  37. x = self.l[0]+self.l[2]
  38. y = self.l[1]+self.l[3]
  39.  
  40.  
  41. class L(object):
  42.  
  43. def __init__(self):
  44.  
  45. self.pos = [22,15]
  46. self.anchor = [1,33]
  47.  
  48. def doit(self):
  49.  
  50. x = self.pos[0]+self.anchor[0]
  51. y = self.pos[1]+self.anchor[1]
  52.  
  53.  
  54. class T(object):
  55.  
  56. def __init__(self):
  57.  
  58. self.pos = (22,15)
  59. self.anchor = (1,33)
  60.  
  61. def doit(self):
  62.  
  63. x = self.pos[0]+self.anchor[0]
  64. y = self.pos[1]+self.anchor[1]
  65.  
  66.  
  67. class V(object):
  68.  
  69. def __init__(self):
  70.  
  71. self.pos_x = 22
  72. self.pos_y = 15
  73. self.anchor_x = 1
  74. self.anchor_y = 33
  75.  
  76. def doit(self):
  77.  
  78. x = self.pos_x+self.anchor_y
  79. y = self.pos_y+self.anchor_y
  80.  
  81.  
  82. n = 200000
  83.  
  84. a = DD()
  85. t = time.clock()
  86. for i in xrange(n):
  87. a.doit()
  88. print(time.clock()-t)
  89.  
  90. a = D()
  91. t = time.clock()
  92. for i in xrange(n):
  93. a.doit()
  94. print(time.clock()-t)
  95.  
  96. a = LL()
  97. t = time.clock()
  98. for i in xrange(n):
  99. a.doit()
  100. print(time.clock()-t)
  101.  
  102. a = L()
  103. t = time.clock()
  104. for i in xrange(n):
  105. a.doit()
  106. print(time.clock()-t)
  107.  
  108. a = T()
  109. t = time.clock()
  110. for i in xrange(n):
  111. a.doit()
  112. print(time.clock()-t)
  113.  
  114. a = V()
  115. t = time.clock()
  116. for i in xrange(n):
  117. a.doit()
  118. print(time.clock()-t)
  119.  
Success #stdin #stdout 1.09s 8968KB
stdin
Standard input is empty
stdout
0.200753
0.175003
0.168505
0.168046
0.180354
0.186063