Skip to content

Commit

Permalink
TST Benchmark package load time (pyodide#3030)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking13 authored Aug 30, 2022
1 parent b64c32c commit 7010d26
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ jobs:
make npm-link
mkdir test-results
pip install pytest-pyodide
pip install -r requirements.txt
npm install -g node-fetch@2
if [ -z "<< parameters.cache-dir >>" ]; then
export CACHE_DIR=".test_cache/.pytest_cache_$(echo $RANDOM | md5sum | head -c 10)"
Expand All @@ -271,6 +272,8 @@ jobs:
--junitxml=test-results/junit.xml \
--verbose \
--durations 50 \
--benchmark-json=benchmark-time.json \
--benchmark-columns=mean,min,max,stddev \
<< parameters.test-params >> \
-o cache_dir=$CACHE_DIR
- store_test_results:
Expand Down
66 changes: 40 additions & 26 deletions packages/_tests/test_packages_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import functools
import os
import time
from typing import Any

import pytest
from pytest_pyodide.runner import _BrowserBaseRunner
Expand Down Expand Up @@ -44,7 +46,14 @@ def test_parse_package(name: str) -> None:
@pytest.mark.skip_refcount_check
@pytest.mark.driver_timeout(60)
@pytest.mark.parametrize("name", registered_packages())
def test_import(name: str, selenium_standalone: _BrowserBaseRunner) -> None:
@pytest.mark.benchmark(
max_time=3,
min_rounds=1,
timer=time.time,
)
def test_import(
name: str, selenium_standalone: _BrowserBaseRunner, benchmark: Any
) -> None:
if not package_is_built(name):
raise AssertionError(
"Implementation error. Test for an unbuilt package "
Expand All @@ -70,30 +79,35 @@ def test_import(name: str, selenium_standalone: _BrowserBaseRunner) -> None:
))
"""
)
for import_name in meta.get("test", {}).get("imports", []):
selenium_standalone.run_async("import %s" % import_name)
# Make sure that even after importing, there are no additional .pyc
# files
assert (
selenium_standalone.run(
"""
len(list(glob.glob(
site.getsitepackages()[0] + '/**/*.pyc',
recursive=True)
))
"""
)
== baseline_pyc

def _import_pkg():
for import_name in meta.get("test", {}).get("imports", []):
selenium_standalone.run_async("import %s" % import_name)

benchmark(_import_pkg)

# Make sure that even after importing, there are no additional .pyc
# files
assert (
selenium_standalone.run(
"""
len(list(glob.glob(
site.getsitepackages()[0] + '/**/*.pyc',
recursive=True)
))
"""
)
# Make sure no exe files were loaded!
assert (
selenium_standalone.run(
"""
len(list(glob.glob(
site.getsitepackages()[0] + '/**/*.exe',
recursive=True)
))
"""
)
== 0
== baseline_pyc
)
# Make sure no exe files were loaded!
assert (
selenium_standalone.run(
"""
len(list(glob.glob(
site.getsitepackages()[0] + '/**/*.exe',
recursive=True)
))
"""
)
== 0
)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
pytest-asyncio
pytest-cov
pytest-httpserver
pytest-benchmark

0 comments on commit 7010d26

Please sign in to comment.