]> granicus.if.org Git - python/commitdiff
Issue #4677: add two list comprehension tests to pybench.
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 27 Dec 2008 20:34:52 +0000 (20:34 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 27 Dec 2008 20:34:52 +0000 (20:34 +0000)
Misc/NEWS
Tools/pybench/Lists.py

index 64ff4062c86a9eb19424e6e724fb1e8467f48caa..3fc5664b35fa9c09c4ed52ce1a51db1fb36aaa80 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -190,6 +190,11 @@ Library
 - 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
 -----
 
index 67760db35034907a42bf1c3ac5b10405f6924e9d..6c297a3416b2f1f96d4037c2b54d7acb59905b05 100644 (file)
@@ -293,3 +293,58 @@ class SmallLists(Test):
 
         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