Commits

Anonymous committed ee1a5eb

Add class and instance vars to the timings.

  • Participants
  • Parent commits 07401df

Comments (0)

Files changed (1)

File timings/time_variable_access.py

     return inner
 
 read_nonlocal = make_nonlocal_reader()
-    
+
 v_global = None
 def read_global(trials=trials):
     for t in trials:
         v_global; v_global; v_global; v_global; v_global
 
 def read_builtin(trials=trials):
-    v_local = None
     for t in trials:
         oct; oct; oct; oct; oct
         oct; oct; oct; oct; oct
         oct; oct; oct; oct; oct
         oct; oct; oct; oct; oct
 
+class A:
+    pass
+
+def read_classvar(trials=trials, A=A):
+    A.x = None
+    for t in trials:
+        A.x;    A.x;    A.x;    A.x;    A.x
+        A.x;    A.x;    A.x;    A.x;    A.x
+        A.x;    A.x;    A.x;    A.x;    A.x
+        A.x;    A.x;    A.x;    A.x;    A.x
+        A.x;    A.x;    A.x;    A.x;    A.x
+
+def read_instancevar(trials=trials, a=A()):
+    a.x = None
+    for t in trials:
+        a.x;    a.x;    a.x;    a.x;    a.x
+        a.x;    a.x;    a.x;    a.x;    a.x
+        a.x;    a.x;    a.x;    a.x;    a.x
+        a.x;    a.x;    a.x;    a.x;    a.x
+        a.x;    a.x;    a.x;    a.x;    a.x
+
 def write_local(trials=trials):
     v_local = None
     for t in trials:
         v_global = None; v_global = None; v_global = None; v_global = None; v_global = None
         v_global = None; v_global = None; v_global = None; v_global = None; v_global = None
 
+def write_classvar(trials=trials, A=A):
+    for t in trials:
+        A.x = None;    A.x = None;    A.x = None;    A.x = None;    A.x = None
+        A.x = None;    A.x = None;    A.x = None;    A.x = None;    A.x = None
+        A.x = None;    A.x = None;    A.x = None;    A.x = None;    A.x = None
+        A.x = None;    A.x = None;    A.x = None;    A.x = None;    A.x = None
+        A.x = None;    A.x = None;    A.x = None;    A.x = None;    A.x = None
+
+def write_instancevar(trials=trials, a=A()):
+    for t in trials:
+        a.x = None;    a.x = None;    a.x = None;    a.x = None;    a.x = None
+        a.x = None;    a.x = None;    a.x = None;    a.x = None;    a.x = None
+        a.x = None;    a.x = None;    a.x = None;    a.x = None;    a.x = None
+        a.x = None;    a.x = None;    a.x = None;    a.x = None;    a.x = None
+        a.x = None;    a.x = None;    a.x = None;    a.x = None;    a.x = None
+
 def loop_overhead(trials=trials):
     for t in trials:
         pass
     from timeit import Timer
 
     for f in [read_local, read_nonlocal, read_global, read_builtin,
-              write_local, write_nonlocal, write_global, loop_overhead]:
-        print(min(Timer(f).repeat(7, 1000)), f.__name__, sep='\t')
+              read_classvar, read_instancevar,
+              write_local, write_nonlocal, write_global,
+              write_classvar, write_instancevar,
+              loop_overhead]:
+        print('{:5.3f}\t{}'.format(min(Timer(f).repeat(7, 1000)), f.__name__))