Commits

Anonymous committed 20dda6c Draft

Add 1 instead of None

Comments (0)

Files changed (1)

timings/time_variable_access.py

 # Show relative speeds of local, nonlocal, global, and built-in access.
 
-trials = [None] * 500
+trials = [1] * 500
 
 def read_local(trials=trials):
-    v_local = None
+    v_local = 1
     for t in trials:
         v_local;    v_local;    v_local;    v_local;    v_local
         v_local;    v_local;    v_local;    v_local;    v_local
         v_local;    v_local;    v_local;    v_local;    v_local
 
 def make_nonlocal_reader():
-    v_nonlocal = None
+    v_nonlocal = 1
     def inner(trials=trials):
         for t in trials:
             v_nonlocal; v_nonlocal; v_nonlocal; v_nonlocal; v_nonlocal
 
 read_nonlocal = make_nonlocal_reader()
 
-v_global = None
+v_global = 1
 def read_global(trials=trials):
     for t in trials:
         v_global; v_global; v_global; v_global; v_global
         pass
 
 def read_classvar(trials=trials, A=A):
-    A.x = None
+    A.x = 1
     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
 
 def read_instancevar(trials=trials, a=A()):
-    a.x = None
+    a.x = 1
     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.m;    a.m;    a.m;    a.m;    a.m
 
 def write_local(trials=trials):
-    v_local = None
+    v_local = 1
     for t in trials:
-        v_local = None; v_local = None; v_local = None; v_local = None; v_local = None
-        v_local = None; v_local = None; v_local = None; v_local = None; v_local = None
-        v_local = None; v_local = None; v_local = None; v_local = None; v_local = None
-        v_local = None; v_local = None; v_local = None; v_local = None; v_local = None
-        v_local = None; v_local = None; v_local = None; v_local = None; v_local = None
+        v_local = 1; v_local = 1; v_local = 1; v_local = 1; v_local = 1
+        v_local = 1; v_local = 1; v_local = 1; v_local = 1; v_local = 1
+        v_local = 1; v_local = 1; v_local = 1; v_local = 1; v_local = 1
+        v_local = 1; v_local = 1; v_local = 1; v_local = 1; v_local = 1
+        v_local = 1; v_local = 1; v_local = 1; v_local = 1; v_local = 1
 
 def make_nonlocal_writer():
-    v_nonlocal = None
+    v_nonlocal = 1
     def inner(trials=trials):
         nonlocal v_nonlocal
         for t in trials:
-            v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None
-            v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None
-            v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None
-            v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None
-            v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None; v_nonlocal = None
+            v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1
+            v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1
+            v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1
+            v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1
+            v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1; v_nonlocal = 1
     inner.__name__ = 'write_nonlocal'
     return inner
 
 def write_global(trials=trials):
     global v_global
     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
-        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
-        v_global = None; v_global = None; v_global = None; v_global = None; v_global = None
+        v_global = 1; v_global = 1; v_global = 1; v_global = 1; v_global = 1
+        v_global = 1; v_global = 1; v_global = 1; v_global = 1; v_global = 1
+        v_global = 1; v_global = 1; v_global = 1; v_global = 1; v_global = 1
+        v_global = 1; v_global = 1; v_global = 1; v_global = 1; v_global = 1
+        v_global = 1; v_global = 1; v_global = 1; v_global = 1; v_global = 1
 
 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
+        A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1
+        A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1
+        A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1
+        A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1
+        A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1;    A.x = 1
 
 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
+        a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1
+        a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1
+        a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1
+        a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1
+        a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1;    a.x = 1
 
 def loop_overhead(trials=trials):
     for t in trials: