Skip to content

Commit 2e133ce

Browse files
committed
Type erasure
1 parent 9f45ae0 commit 2e133ce

File tree

18 files changed

+424
-208
lines changed

18 files changed

+424
-208
lines changed

Makefile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
.PHONY: test clean format check publish docs
1+
.PHONY: test-opt test-src clean format check publish docs opt
22

3-
test:
4-
python -m pytest
3+
test-opt: opt
4+
cd opt/ && python -m pytest
5+
6+
test-src:
7+
cd src/ && python -m pytest
58

69
clean:
7-
rm -r `find . -iname "__pycache__" -type d` || true
8-
rm -r .hypothesis/ .pytest_cache/ dist/ raffiot.egg-info/ || true
10+
./clean.sh
911

1012
format:
11-
black `find raffiot/ tests/ -iname "*.py" -type f`
13+
black `find . -iname "*.py" -type f`
1214

13-
check: format test docs clean
15+
check: format test-src clean test-opt docs
1416

1517
publish: check
16-
python setup.py sdist
17-
twine upload dist/*
18+
./clean.sh
19+
./opt.sh
20+
cd opt/ && python setup.py sdist
21+
cd opt/ && twine upload dist/*
1822

1923
docs:
2024
rm -r docs/ || true
21-
pdoc3 --html raffiot -o docs/
25+
cd src/ && pdoc3 --html raffiot -o ../docs/
2226
mv docs/raffiot/* docs/
2327
rm -r docs/raffiot/
28+
29+
opt: clean
30+
./opt.sh

benchmarks/fibonacci.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sys
2+
import statistics
3+
from timeit import default_timer as timer
4+
from raffiot import io
5+
from raffiot.io import IO
6+
7+
n = int(sys.argv[1])
8+
t = int(sys.argv[2])
9+
10+
def fibo(u0: int, u1: int, i: int) -> int:
11+
if i > 1:
12+
return fibo(u1, u0 + u1, i-1)
13+
if i == 1:
14+
return u1
15+
return u0
16+
17+
def fibo_io(u0: int, u1: int, i: int) -> IO:
18+
if i > 1:
19+
return io.defer_io(lambda: fibo_io(u1, u0 + u1, i-1))
20+
if i == 1:
21+
return io.pure(u1)
22+
return io.pure(u0)
23+
24+
def mesure(nb):
25+
l = []
26+
i = 0
27+
while i < 10 * nb:
28+
start = timer()
29+
fibo(0,1,n)
30+
end = timer()
31+
l.append(end - start)
32+
i += 1
33+
return statistics.median(l)
34+
35+
def mesure_io(nb):
36+
l = []
37+
i = 0
38+
mio = fibo_io(0,1,n)
39+
while i < nb:
40+
start = timer()
41+
mio.run(None)
42+
end = timer()
43+
l.append(end - start)
44+
i += 1
45+
return statistics.median(l)
46+
47+
print(io.marker)
48+
print(f"fibo({n}) : {mesure(t)}")
49+
print(f"fibo_io({n}) : {mesure_io(t)}")
50+
print(f"fibo({n}) : {mesure(t)}")
51+
print(f"fibo_io({n}) : {mesure_io(t)}")

benchmarks/imeprofile.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import cProfile, pstats
2+
from raffiot import io
3+
from raffiot.io import IO
4+
import sys
5+
6+
def fibo_io(u0: int, u1: int, i: int) -> IO:
7+
if i > 1:
8+
return io.defer_io(lambda: fibo_io(u1, (u0 + u1) % 10000, i-1))
9+
if i == 1:
10+
return io.pure(u1)
11+
return io.pure(u0)
12+
13+
m = fibo_io(0,1,int(sys.argv[1]))
14+
15+
16+
profiler = cProfile.Profile()
17+
profiler.enable()
18+
m.run(None)
19+
profiler.disable()
20+
stats = pstats.Stats(profiler).sort_stats('cumtime')
21+
stats.print_stats()
22+

clean.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
rm -r opt || true
3+
rm -r `find . -type d -and \( -iname ".hypothesis" -or -iname ".pytest_cache" -or -iname "dist" -or -iname "raffiot.egg-info" -or -iname "__pycache__" \)` || true

conda/raffiot/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set name = "raffiot" %}
2-
{% set version = "0.0.5" %}
2+
{% set version = "0.0.6" %}
33

44
package:
55
name: "{{ name|lower }}"

0 commit comments

Comments
 (0)