-
-
Save isidentical/325325766daf7d3588b50704ef7bf064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From https://github.com/ichard26 | |
import tempfile | |
from pathlib import Path | |
import pyperf | |
import black | |
from blib2to3 import pygram | |
# First try the relevant function post-refactor in 21.5b1, and fallback | |
# to old function location. | |
try: | |
from black.parsing import lib2to3_parse | |
except ImportError: | |
from black import lib2to3_parse | |
runner = pyperf.Runner() | |
code = Path("<file>").read_text(encoding="utf8") | |
with tempfile.TemporaryDirectory(prefix="blackbench-parsing-") as path: | |
# Block the parser code from using any pre-existing cache. | |
pygram.initialize(path) | |
runner.bench_func("-t py39 (<branch>): ", lib2to3_parse, code, set((black.TargetVersion.PY39,))) | |
runner.bench_func("-t py310 (<branch>): ", lib2to3_parse, code, set((black.TargetVersion.PY310,))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment