"""
This example illustrates mixing interpreted and compilable code.

The file ex2.sage contains the interpeted code and ex2.spyx
the compilable code.

See how much the compiled one speeds things up!!

    sage: time foo2(10^7)     # non-compiled
    1000000000000000006364
    Time: CPU 2.14 s, Wall: 2.22 s
    sage: time foo(10^7)      # compiled
    1000000000000000006364
    Time: CPU 0.15 s, Wall: 0.17 s

It's almost 15 times as fast.

    sage: time foo(10^8)
    1000000000000000000001176
    Time: CPU 2.25 s, Wall: 2.30 s
    sage: time foo2(10^8)
    1000000000000000000001176
    Time: CPU 21.97 s, Wall: 23.02 s
"""

os.chdir("/home/was/.sage//tmp//pyrex/ex20"); from ex20 import *; os.chdir("/home/was/s/examples/pyrex")

def foo(n):
    return n**ZZ(3) + bar(n, ZZ(10007))


def foo2(n):
    return n**ZZ(3) + bar2(n,ZZ(10007))

def bar2(n, p):
    return sum(range(n)) % p

def bar2(n, p):
    t = int(ZZ(0))
    p = int(p)
    for s in xrange(n):
        t = (t+s)%p
    return t


