upload exercises
This commit is contained in:
parent
32ad3f2662
commit
d17339a560
75 changed files with 773 additions and 0 deletions
30
exercises/exerciseB/numerical_integration_solution.py
Executable file
30
exercises/exerciseB/numerical_integration_solution.py
Executable file
|
@ -0,0 +1,30 @@
|
|||
import sys
|
||||
from numerical_integration import compute_error
|
||||
|
||||
def main(arg):
|
||||
ns = [10_000, 25_000, 50_000, 75_000]
|
||||
|
||||
match arg:
|
||||
case 'for':
|
||||
errors = []
|
||||
for n in ns:
|
||||
errors += [compute_error(n)]
|
||||
case 'lc':
|
||||
errors = [compute_error(n) for n in ns]
|
||||
case 'map':
|
||||
errors = list(map(compute_error, ns))
|
||||
case 'mp':
|
||||
from multiprocessing import Pool as ProcessPool
|
||||
with ProcessPool() as pool:
|
||||
errors = pool.map(compute_error, ns)
|
||||
case 'mt':
|
||||
from multiprocessing.pool import ThreadPool
|
||||
with ThreadPool(10) as pool:
|
||||
errors = pool.map(compute_error, ns)
|
||||
|
||||
for n, e in zip(ns, errors):
|
||||
print(f'{n} {e:.8%}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
arg = (sys.argv[1:] + ['for'])[0]
|
||||
main(arg)
|
Loading…
Add table
Add a link
Reference in a new issue