[Python-checkins] r67965 - in python/trunk: Misc/NEWS Tools/pybench/Lists.py

antoine.pitrou python-checkins at python.org
Sat Dec 27 21:34:52 CET 2008


Author: antoine.pitrou
Date: Sat Dec 27 21:34:52 2008
New Revision: 67965

Log:
Issue #4677: add two list comprehension tests to pybench.



Modified:
   python/trunk/Misc/NEWS
   python/trunk/Tools/pybench/Lists.py

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat Dec 27 21:34:52 2008
@@ -190,6 +190,11 @@
 - Issue #4730: Fixed the cPickle module to handle correctly astral characters
   when protocol 0 is used.
 
+Tools/Demos
+-----------
+
+- Issue #4677: add two list comprehension tests to pybench.
+
 Build
 -----
 

Modified: python/trunk/Tools/pybench/Lists.py
==============================================================================
--- python/trunk/Tools/pybench/Lists.py	(original)
+++ python/trunk/Tools/pybench/Lists.py	Sat Dec 27 21:34:52 2008
@@ -293,3 +293,58 @@
 
         for i in xrange(self.rounds):
             pass
+
+class SimpleListComprehensions(Test):
+
+    version = 2.0
+    operations = 6
+    rounds = 20000
+
+    def test(self):
+
+        n = range(10) * 10
+
+        for i in xrange(self.rounds):
+            l = [x for x in n]
+            l = [x for x in n if x]
+            l = [x for x in n if not x]
+
+            l = [x for x in n]
+            l = [x for x in n if x]
+            l = [x for x in n if not x]
+
+    def calibrate(self):
+
+        n = range(10) * 10
+
+        for i in xrange(self.rounds):
+            pass
+
+class NestedListComprehensions(Test):
+
+    version = 2.0
+    operations = 6
+    rounds = 20000
+
+    def test(self):
+
+        m = range(10)
+        n = range(10)
+
+        for i in xrange(self.rounds):
+            l = [x for x in n for y in m]
+            l = [y for x in n for y in m]
+
+            l = [x for x in n for y in m if y]
+            l = [y for x in n for y in m if x]
+
+            l = [x for x in n for y in m if not y]
+            l = [y for x in n for y in m if not x]
+
+    def calibrate(self):
+
+        m = range(10)
+        n = range(10)
+
+        for i in xrange(self.rounds):
+            pass


More information about the Python-checkins mailing list