mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
[3.9] [3.10] bpo-46576: bpo-46524: Disable compiler optimization within test_peg_generator. (GH-31015) (GH-31089) (GH-31093)
Disable compiler optimization within test_peg_generator. This speed up test_peg_generator by always disabling compiler optimizations by using -O0 or equivalent when the test is building its own C extensions. A build not using --with-pydebug in order to speed up test execution winds up with this test taking a very long time as it would do repeated compilation of parser C code using the same optimization flags as CPython was built with. This speeds the test up 6-8x on gps-raspbian. Also incorporate's GH-31017's win32 conditional and flags. Co-authored-by: Kumar Aditya kumaraditya303. (cherry picked from commit164a017e13
) Co-authored-by: Gregory P. Smith <greg@krypto.org> (cherry picked from commitf5ebec4d3e
) Co-authored-by: Gregory P. Smith <greg@krypto.org> Automerge-Triggered-By: GH:gpshead
This commit is contained in:
parent
fafd2dadf6
commit
e8258608c2
2 changed files with 13 additions and 0 deletions
|
@ -0,0 +1,3 @@
|
|||
test_peg_generator now disables compiler optimization when testing
|
||||
compilation of its own C extensions to significantly speed up the
|
||||
testing on non-debug builds of CPython.
|
|
@ -1,6 +1,7 @@
|
|||
import pathlib
|
||||
import shutil
|
||||
import tokenize
|
||||
import sys
|
||||
import sysconfig
|
||||
import tempfile
|
||||
import itertools
|
||||
|
@ -33,6 +34,7 @@ def compile_c_extension(
|
|||
build_dir: Optional[str] = None,
|
||||
verbose: bool = False,
|
||||
keep_asserts: bool = True,
|
||||
disable_optimization: bool = True, # Significant test_peg_generator speedup.
|
||||
) -> str:
|
||||
"""Compile the generated source for a parser generator into an extension module.
|
||||
|
||||
|
@ -59,6 +61,14 @@ def compile_c_extension(
|
|||
extra_link_args = get_extra_flags("LDFLAGS", "PY_LDFLAGS_NODIST")
|
||||
if keep_asserts:
|
||||
extra_compile_args.append("-UNDEBUG")
|
||||
if disable_optimization:
|
||||
if sys.platform == 'win32':
|
||||
extra_compile_args.append("/Od")
|
||||
extra_link_args.append("/LTCG:OFF")
|
||||
else:
|
||||
extra_compile_args.append("-O0")
|
||||
if sysconfig.get_config_var("GNULD") == "yes":
|
||||
extra_link_args.append("-fno-lto")
|
||||
extension = [
|
||||
Extension(
|
||||
extension_name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue