Commit 95379aa0 authored by Roman Yurchak's avatar Roman Yurchak Committed by GitHub

Merge pull request #202 from mdboom/fix-benchmarks

Fix benchmarks in light of recent changes
parents 14847db0 370a4f06
...@@ -19,21 +19,29 @@ jobs: ...@@ -19,21 +19,29 @@ jobs:
# Set up the Debian testing repo, and then install g++ from there... # Set up the Debian testing repo, and then install g++ from there...
sudo bash -c "echo \"deb http://ftp.us.debian.org/debian testing main contrib non-free\" >> /etc/apt/sources.list" sudo bash -c "echo \"deb http://ftp.us.debian.org/debian testing main contrib non-free\" >> /etc/apt/sources.list"
sudo apt-get update sudo apt-get update
sudo apt-get install node-less cmake build-essential clang-format-6.0 flake8 uglifyjs python3-yaml chromium ccache sudo apt-get install node-less cmake build-essential clang-format-6.0 uglifyjs chromium ccache
sudo apt-get install -t testing g++-8 sudo apt-get install -t testing g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8
sudo update-alternatives --set gcc /usr/bin/gcc-8 sudo update-alternatives --set gcc /usr/bin/gcc-8
sudo ln -s /usr/bin/clang-format-6.0 /usr/bin/clang-format sudo ln -s /usr/bin/clang-format-6.0 /usr/bin/clang-format
# Install Python dependencies
sudo pip install virtualenv sudo pip install virtualenv
virtualenv pyodide-env virtualenv pyodide-env
source pyodide-env/bin/activate source pyodide-env/bin/activate
pip install pytest pytest-xdist pytest-instafail selenium PyYAML flake8
pip install pytest pytest-xdist pytest-instafail selenium PyYAML # Get recent version of Firefox and geckodriver
wget -O firefox.tar.bz2 https://download.mozilla.org/\?product\=firefox-latest-ssl\&os\=linux64\&lang\=en-US
tar jxf firefox.tar.bz2
wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz
tar zxf geckodriver-v0.21.0-linux64.tar.gz -C firefox
# Get recent version of chromedriver
wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver pyodide-env/bin/
- run: - run:
name: lint name: lint
...@@ -69,6 +77,8 @@ jobs: ...@@ -69,6 +77,8 @@ jobs:
paths: paths:
- ./build - ./build
- ./pyodide-env - ./pyodide-env
- ./cpython/build/3.7.0/host
- ./firefox
- store_artifacts: - store_artifacts:
path: /home/circleci/repo/build/ path: /home/circleci/repo/build/
...@@ -86,12 +96,6 @@ jobs: ...@@ -86,12 +96,6 @@ jobs:
# causes Firefox to complain when loading it. Let's just add the new mime type. # causes Firefox to complain when loading it. Let's just add the new mime type.
sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types" sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types"
# Get recent version of Firefox and geckodriver
wget -O firefox.tar.bz2 https://download.mozilla.org/\?product\=firefox-latest-ssl\&os\=linux64\&lang\=en-US
tar jxf firefox.tar.bz2
wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz
tar zxf geckodriver-v0.21.0-linux64.tar.gz -C firefox
source pyodide-env/bin/activate source pyodide-env/bin/activate
export PATH=$PWD/firefox:$PATH export PATH=$PWD/firefox:$PATH
pytest test -v -k firefox pytest test -v -k firefox
...@@ -109,14 +113,35 @@ jobs: ...@@ -109,14 +113,35 @@ jobs:
# causes Firefox to complain when loading it. Let's just add the new mime type. # causes Firefox to complain when loading it. Let's just add the new mime type.
sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types" sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types"
# Get recent version of chromedriver
wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver pyodide-env/bin/
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: dependencies
command: |
sudo bash -c "echo \"deb http://ftp.us.debian.org/debian testing main contrib non-free\" >> /etc/apt/sources.list"
sudo apt-get update
sudo apt-get install -t testing g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8
sudo update-alternatives --set gcc /usr/bin/gcc-8
- run:
name: benchmark
command: |
sudo bash -c "echo 'application/wasm wasm' >> /etc/mime.types"
source pyodide-env/bin/activate
export PATH=$PWD/firefox:$PATH
python benchmark/benchmark.py cpython/build/3.7.0/host/bin/python3 build/benchmarks.json
- store_artifacts:
path: /home/circleci/repo/build
deploy: deploy:
machine: machine:
enabled: true enabled: true
...@@ -141,6 +166,9 @@ workflows: ...@@ -141,6 +166,9 @@ workflows:
- test-firefox: - test-firefox:
requires: requires:
- build - build
- benchmark:
requires:
- build
- deploy: - deploy:
requires: requires:
- test-chrome - test-chrome
......
...@@ -122,7 +122,7 @@ lint: ...@@ -122,7 +122,7 @@ lint:
clang-format -output-replacements-xml src/*.c src/*.h src/*.js | (! grep '<replacement ') clang-format -output-replacements-xml src/*.c src/*.h src/*.js | (! grep '<replacement ')
benchmark: all build/test.html benchmark: all
python benchmark/benchmark.py $(HOSTPYTHON) build/benchmarks.json python benchmark/benchmark.py $(HOSTPYTHON) build/benchmarks.json
python benchmark/plot_benchmark.py build/benchmarks.json build/benchmarks.png python benchmark/plot_benchmark.py build/benchmarks.json build/benchmarks.png
......
...@@ -10,7 +10,7 @@ sys.path.insert( ...@@ -10,7 +10,7 @@ sys.path.insert(
import conftest # noqa import conftest # noqa
SKIP = set(['fft', 'hyantes']) SKIP = set(['fft', 'hyantes', 'README'])
def run_native(hostpython, code): def run_native(hostpython, code):
...@@ -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,
...@@ -74,9 +74,9 @@ def parse_numpy_benchmark(filename): ...@@ -74,9 +74,9 @@ def parse_numpy_benchmark(filename):
def get_numpy_benchmarks(): def get_numpy_benchmarks():
root = Path('../numpy-benchmarks/benchmarks') root = Path(__file__).resolve().parent / '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