Skip to content

Add mypy_types benchmark #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pyperformance/benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import platform

from pyperformance.run import run_perf_script

Expand Down Expand Up @@ -65,6 +66,16 @@
'xml_etree',
]

CPYTHON_ONLY_GROUP = [
# mypy is CPython only as of now. In the future it may not be.
'mypy_types',
]

IS_CPYTHON = platform.python_implementation() == "CPython"

if IS_CPYTHON:
DEFAULT_GROUP.extend(CPYTHON_ONLY_GROUP)

BENCH_GROUPS = {
# get_benchmarks() creates an "all" group which includes every benchmark
# pyperformance knows about.
Expand Down Expand Up @@ -288,6 +299,9 @@ def BM_sqlalchemy_imperative(python, options):
def BM_mdp(python, options):
return run_perf_script(python, options, "mdp")

if IS_CPYTHON:
def BM_mypy_types(python, options):
return run_perf_script(python, options, "mypy_types")

# End benchmarks, begin main entry point support.

Expand Down
31 changes: 31 additions & 0 deletions pyperformance/benchmarks/bm_mypy_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This benchmark is adapted from the Pyston python-macrobenchmarks repo,
# licensed under the MIT license.
# source: https://github.com/pyston/python-macrobenchmarks/blob/main/benchmarks/mypy_bench.py
# commit: 0fcc5299e6fefba7eefcacd4aceb112971d48c7b on 21 Oct 2020.
# license: https://github.com/pyston/python-macrobenchmarks/blob/main/LICENSE
# It has been updated and modified for pyperformance.
# The benchmark runs mypy against its own types file multiple times.

import os

import pyperf

from mypy.main import main


def typecheck_targets(targets):
with open(os.devnull, 'w') as devnull:
try:
main(None, devnull, devnull, targets)
except SystemExit:
pass


if __name__ == '__main__':
runner = pyperf.Runner()
runner.metadata['description'] = ('Mypy benchmark: '
'type-check mypy/types.py')
target_path = os.path.join(os.path.dirname(__file__), 'data',
'bm_mypy_target.py')
runner.bench_func('mypy_types', typecheck_targets, [target_path])

Loading