Last active
July 2, 2023 03:57
-
-
Save thuwarakeshm/7f8f8032ef4a4f52249e7865c4ace6cb to your computer and use it in GitHub Desktop.
CPython Challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cProfile | |
| from fib import fib as fibc | |
| cProfile.run("fibc(35)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cProfile | |
| from multiprocessing import Pool | |
| from fib import fib as fibc | |
| if __name__ == "__main__": | |
| with Pool(5) as p: | |
| print(cProfile.run("p.map(fibc, [20, 25, 30, 35, 40])")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fib(n: int): | |
| """This function calculates Fibonacci number.""" | |
| return n if n < 2 else fib(n - 1) + fib(n - 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cProfile | |
| def fib(n: int): | |
| """This function calculates Fibonacci number.""" | |
| return n if n < 2 else fib(n - 1) + fib(n - 2) | |
| cProfile.run("fib(35)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cProfile | |
| from multiprocessing import Pool | |
| def fib(n: int): | |
| """This function calculates Fibonacci number.""" | |
| return n if n < 2 else fib(n - 1) + fib(n - 2) | |
| if __name__ == "__main__": | |
| with Pool(5) as p: | |
| print(cProfile.run("p.map(fib, [20, 25, 30, 35, 40])")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from setuptools import setup | |
| from Cython.Build import cythonize | |
| setup( | |
| ext_modules = cythonize("fib.pyx") | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cProfile | |
| from tuplex import * | |
| c = Context() | |
| def fib(n: int): | |
| """This function calculates Fibonacci number.""" | |
| return n if n < 2 else fib(n - 1) + fib(n - 2) | |
| def fib_tuplex(): | |
| c.parallelize([35]).map(fib).collect() | |
| cProfile.run("fib_tuplex()") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cProfile | |
| from cprime import count_primes | |
| from tuplex import * | |
| c = Context() | |
| def fib_tuplex(): | |
| c.parallelize([20, 25, 30, 35, 40]).map(fib).collect() | |
| cProfile.run("fib_tuplex()") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment