Commit a685f18f authored by Michael Droettboom's avatar Michael Droettboom

Fix benchmarks in light of recent changes

parent 27d135e6
...@@ -117,6 +117,21 @@ jobs: ...@@ -117,6 +117,21 @@ jobs:
source pyodide-env/bin/activate source pyodide-env/bin/activate
pytest test -v -k chrome pytest test -v -k chrome
benchmark:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: .
- run:
name: benchmark
command: |
sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types"
source pyodide-env/bin/activate
export PATH=$PWD/firefox:$PATH
make benchmark
deploy: deploy:
machine: machine:
enabled: true enabled: true
...@@ -141,6 +156,9 @@ workflows: ...@@ -141,6 +156,9 @@ workflows:
- test-firefox: - test-firefox:
requires: requires:
- build - build
- benchmark:
requires:
- build
- deploy: - deploy:
requires: requires:
- test-chrome - test-chrome
......
...@@ -25,27 +25,27 @@ def run_native(hostpython, code): ...@@ -25,27 +25,27 @@ def run_native(hostpython, code):
return float(output.strip().split()[-1]) return float(output.strip().split()[-1])
def run_wasm(code, cls): def run_wasm(code, cls, port):
s = cls() s = cls(port)
try: try:
s.load_package('numpy') s.load_package('numpy')
s.run(code) s.run(code)
try: try:
runtime = float(s.logs[-1]) runtime = float(s.logs.split('\n')[-1])
except ValueError: except ValueError:
print('\n'.join(s.logs)) print(s.logs)
raise raise
finally: finally:
s.driver.quit() s.driver.quit()
return runtime return runtime
def run_all(hostpython, code): def run_all(hostpython, port, code):
a = run_native(hostpython, code) a = run_native(hostpython, code)
print("native:", a) print("native:", a)
b = run_wasm(code, conftest.FirefoxWrapper) b = run_wasm(code, conftest.FirefoxWrapper, port)
print("firefox:", b) print("firefox:", b)
c = run_wasm(code, conftest.ChromeWrapper) c = run_wasm(code, conftest.ChromeWrapper, port)
print("chrome:", c) print("chrome:", c)
result = { result = {
'native': a, 'native': a,
...@@ -76,7 +76,7 @@ def parse_numpy_benchmark(filename): ...@@ -76,7 +76,7 @@ def parse_numpy_benchmark(filename):
def get_numpy_benchmarks(): def get_numpy_benchmarks():
root = Path('../numpy-benchmarks/benchmarks') root = Path('../numpy-benchmarks/benchmarks')
for filename in root.iterdir(): for filename in root.iterdir():
name = filename.name name = filename.stem
if name in SKIP: if name in SKIP:
continue continue
content = parse_numpy_benchmark(filename) content = parse_numpy_benchmark(filename)
...@@ -87,6 +87,8 @@ def get_numpy_benchmarks(): ...@@ -87,6 +87,8 @@ def get_numpy_benchmarks():
"from timeit import Timer\n" "from timeit import Timer\n"
"t = Timer(run, setup)\n" "t = Timer(run, setup)\n"
"r = t.repeat(11, 40)\n" "r = t.repeat(11, 40)\n"
"r.remove(min(r))\n"
"r.remove(max(r))\n"
"print(np.mean(r))\n".format(name)) "print(np.mean(r))\n".format(name))
yield name, content yield name, content
...@@ -97,10 +99,11 @@ def get_benchmarks(): ...@@ -97,10 +99,11 @@ def get_benchmarks():
def main(hostpython): def main(hostpython):
results = {} with conftest.spawn_web_server() as (hostname, port, log_path):
for k, v in get_benchmarks(): results = {}
print(k) for k, v in get_benchmarks():
results[k] = run_all(hostpython, v) print(k)
results[k] = run_all(hostpython, port, v)
return results return results
......
...@@ -28,7 +28,7 @@ ax.invert_yaxis() ...@@ -28,7 +28,7 @@ ax.invert_yaxis()
ax.set_xlabel('Slowdown factor (WebAssembly:Native)') ax.set_xlabel('Slowdown factor (WebAssembly:Native)')
ax.set_title('Python benchmarks') ax.set_title('Python benchmarks')
ax.axvline(1.0, color='red') ax.axvline(1.0, color='red')
ax.grid() ax.grid(axis='x')
ax.legend(loc='lower right') ax.legend(loc='lower right')
plt.savefig(sys.argv[-1]) plt.savefig(sys.argv[-1])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment