Commits

Antonio Cuni committed 314ce24 Draft

move stuff around

Comments (0)

Files changed (11)

talks/pypy-course/intro/ctypesbench.py

-import time
-N = 10000000
-
-def main(N):
-    import ctypes
-    libm = ctypes.CDLL('libm.so')
-    pow = libm.pow
-    pow.argtypes = [ctypes.c_double, ctypes.c_double]
-    pow.restype = ctypes.c_double
-    #
-    i = 0
-    res = 0
-    start = time.clock()
-    while i < N:
-        res += pow(2, 3)
-        i += 1
-    end = time.clock()
-    print 'total:', end-start
-    if hasattr(pow, '_ptr'):
-        print 'address:', pow._ptr.getaddr()
-    return res
-
-
-main(N)

talks/pypy-course/intro/excercise/html_fibo.py

-"""
-The most complicate ever way to produce an HTML list of fibonacci numbers
-"""
-
-def fibo():
-    a, b = 1, 1
-    while True:
-        yield a
-        a, b = b, a+b
-
-
-class HtmlTag(object):
-    def __init__(self, f, indent, tag):
-        self.f = f
-        self.tag = tag
-        self.f.write(' ' * indent)
-        self.f.write('<%s>' % tag)
-
-    def __del__(self):
-        self.f.write('</%s>\n' % self.tag)
-
-def html_fibo(f):
-    f.write('<ul>\n')
-    try:
-        for n in fibo():
-            tag = HtmlTag(f, 4, 'li')
-            yield n
-            tag = None
-    finally:
-        tag = None
-        f.write('</ul>\n')
-
-
-def write_file():
-    f = open('fibo.txt', 'w')
-    for n in html_fibo(f):
-        f.write('%d' % n)
-        if n > 100:
-            break
-
-def main():
-    write_file()
-    content = open('fibo.txt').read()
-    print content
-
-if __name__ == '__main__':
-    main()

talks/pypy-course/intro/numpybench.py

-import time
-
-try:
-    import numpypy as numpy
-except ImportError:
-    import numpy
-
-def pyloop(a):
-    sum = 0
-    for i in range(len(a)):
-        sum += a[i]
-    return sum
-
-def c_loop(a):
-    return numpy.sum(a)
-
-a = numpy.zeros(10000000)
-
-x = time.clock()
-sum1 = pyloop(a)
-y = time.clock()
-print 'pyloop: %.4f secs' % (y-x)
-
-x = time.clock()
-sum2 = c_loop(a)
-y = time.clock()
-print 'c_loop: %.4f secs' % (y-x)
-
-assert sum1 == sum2

talks/pypy-course/intro/numpybench2.py

-import time
-
-try:
-    import numpypy as numpy
-except ImportError:
-    import numpy
-
-def pyloop(a, b, c):
-    N = len(a)
-    assert N == len(b) == len(c)
-    res = numpy.zeros(N)
-    for i in range(N):
-        res[i] = a[i] + b[i]*c[i]
-    return res
-
-def c_loop(a, b, c):
-    return numpy.add(a, numpy.multiply(b, c))
-
-a = numpy.zeros(10000000)
-b = numpy.ones(10000000)
-c = numpy.ones(10000000)
-
-x = time.clock()
-res1 = pyloop(a, b, c)
-y = time.clock()
-print 'pyloop: %.4f secs' % (y-x)
-
-x = time.clock()
-res2 = c_loop(a, b, c)
-y = time.clock()
-print 'c_loop: %.4f secs' % (y-x)
-
-assert (res1 == res2).all()

talks/pypy-course/intro/rational.c

-#include <stdio.h>
-
-int main()
-{
-    float px = 0.0, py = 0.0;
-    while (px < 2000.0) {
-        px += 1.0;
-        py += 0.5;
-    }
-    printf("%f %f\n", px, py);
-}

talks/pypy-course/intro/rational.py

-class Point(object):
-
-    def __init__(self, x, y):
-        self.x = x
-        self.y = y
-
-    def __add__(self, other):
-        if not isinstance(other, Point):
-            raise TypeError
-        x1 = self.x + other.x
-        y1 = self.y + other.y
-        return Point(x1, y1)
-
-def main():
-    p = Point(0.0, 0.0)
-    while p.x < 2000.0:
-        p = p + Point(1.0, 0.5)
-    print p.x, p.y
-
-main()
-

talks/pypy-course/intro/src/html_fibo.py

+"""
+The most complicate ever way to produce an HTML list of fibonacci numbers
+"""
+
+def fibo():
+    a, b = 1, 1
+    while True:
+        yield a
+        a, b = b, a+b
+
+
+class HtmlTag(object):
+    def __init__(self, f, indent, tag):
+        self.f = f
+        self.tag = tag
+        self.f.write(' ' * indent)
+        self.f.write('<%s>' % tag)
+
+    def __del__(self):
+        self.f.write('</%s>\n' % self.tag)
+
+def html_fibo(f):
+    f.write('<ul>\n')
+    try:
+        for n in fibo():
+            tag = HtmlTag(f, 4, 'li')
+            yield n
+            tag = None
+    finally:
+        tag = None
+        f.write('</ul>\n')
+
+
+def write_file():
+    f = open('fibo.txt', 'w')
+    for n in html_fibo(f):
+        f.write('%d' % n)
+        if n > 100:
+            break
+
+def main():
+    write_file()
+    content = open('fibo.txt').read()
+    print content
+
+if __name__ == '__main__':
+    main()

talks/pypy-course/intro/src/numpybench.py

+import time
+
+try:
+    import numpypy as numpy
+except ImportError:
+    import numpy
+
+def pyloop(a):
+    sum = 0
+    for i in range(len(a)):
+        sum += a[i]
+    return sum
+
+def c_loop(a):
+    return numpy.sum(a)
+
+a = numpy.zeros(10000000)
+
+x = time.clock()
+sum1 = pyloop(a)
+y = time.clock()
+print 'pyloop: %.4f secs' % (y-x)
+
+x = time.clock()
+sum2 = c_loop(a)
+y = time.clock()
+print 'c_loop: %.4f secs' % (y-x)
+
+assert sum1 == sum2

talks/pypy-course/intro/src/numpybench2.py

+import time
+
+try:
+    import numpypy as numpy
+except ImportError:
+    import numpy
+
+def pyloop(a, b, c):
+    N = len(a)
+    assert N == len(b) == len(c)
+    res = numpy.zeros(N)
+    for i in range(N):
+        res[i] = a[i] + b[i]*c[i]
+    return res
+
+def c_loop(a, b, c):
+    return numpy.add(a, numpy.multiply(b, c))
+
+a = numpy.zeros(10000000)
+b = numpy.ones(10000000)
+c = numpy.ones(10000000)
+
+x = time.clock()
+res1 = pyloop(a, b, c)
+y = time.clock()
+print 'pyloop: %.4f secs' % (y-x)
+
+x = time.clock()
+res2 = c_loop(a, b, c)
+y = time.clock()
+print 'c_loop: %.4f secs' % (y-x)
+
+assert (res1 == res2).all()

talks/pypy-course/intro/src/rational.c

+#include <stdio.h>
+
+int main()
+{
+    float px = 0.0, py = 0.0;
+    while (px < 2000.0) {
+        px += 1.0;
+        py += 0.5;
+    }
+    printf("%f %f\n", px, py);
+}

talks/pypy-course/intro/src/rational.py

+class Point(object):
+
+    def __init__(self, x, y):
+        self.x = x
+        self.y = y
+
+    def __add__(self, other):
+        if not isinstance(other, Point):
+            raise TypeError
+        x1 = self.x + other.x
+        y1 = self.y + other.y
+        return Point(x1, y1)
+
+def main():
+    p = Point(0.0, 0.0)
+    while p.x < 2000.0:
+        p = p + Point(1.0, 0.5)
+    print p.x, p.y
+
+main()
+