A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/exaloop/codon/discussions/178 below:

how faster ? · exaloop/codon · Discussion #178 · GitHub

fibonacci example

$ cat fib.py 

def fib(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fib(n-1) + fib(n-2)

if __name__ == "__main__":
    import sys
    print(fib(int(sys.argv[1])))

CPython 3.11

$ python fib.py 40
102334155
# mem: 8'816_KB
# time: 18.42_s

PyPy 7.3.9

$ pypy fib.py 40
102334155
# mem: 74'596_kB
# time: 4.99_s
# ~= 3.7x

Codon compiled

$ codon build -release fib.py
$ ./fib 40
102334155
# mem: 5'612_kB
# time: 0.26_s
# ~= 70.8x

Codon with python interpreter

# in fibpy.py, we just add `@python` decorator to fib function
$ codon build -release fibpy.py
export CODON_PYTHON=/path/to/libpython3.11.so
$ ./fibpy 40
102334155
# mem: 12'828
# time: 18.49
# ~= 1x

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4