little test for comparing loop code
authorStefan Behnel <scoder@users.berlios.de>
Thu, 6 Mar 2008 08:27:04 +0000 (09:27 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 6 Mar 2008 08:27:04 +0000 (09:27 +0100)
tests/run/addloop.pyx [new file with mode: 0644]

diff --git a/tests/run/addloop.pyx b/tests/run/addloop.pyx
new file mode 100644 (file)
index 0000000..25a82ac
--- /dev/null
@@ -0,0 +1,33 @@
+__doc__ = """
+    >>> x = 1
+    >>> for i in range(10):
+    ...     x = x + i
+    >>> x
+    46
+
+    >>> add_pyrange(10)
+    46
+    >>> add_py(10)
+    46
+    >>> add_c(10)
+    46
+"""
+
+def add_pyrange(max):
+    x = 1
+    for i in range(max):
+        x = x + i
+    return x
+
+def add_py(max):
+    x = 1
+    for i from 0 <= i < max:
+        x = x + i
+    return x
+
+def add_c(max):
+    cdef int x,i
+    x = 1
+    for i from 0 <= i < max:
+        x = x + i
+    return x