mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Refactor scripts in Tools/peg_generator/scripts (GH-20401)
This commit is contained in:
		
							parent
							
								
									2e6593db00
								
							
						
					
					
						commit
						ba6fd87e41
					
				
					 7 changed files with 146 additions and 147 deletions
				
			
		|  | @ -24,7 +24,7 @@ | |||
| argparser.add_argument( | ||||
|     "--parser", | ||||
|     action="store", | ||||
|     choices=["pegen", "cpython"], | ||||
|     choices=["new", "old"], | ||||
|     default="pegen", | ||||
|     help="Which parser to benchmark (default is pegen)", | ||||
| ) | ||||
|  | @ -40,7 +40,12 @@ | |||
| command_compile = subcommands.add_parser( | ||||
|     "compile", help="Benchmark parsing and compiling to bytecode" | ||||
| ) | ||||
| command_parse = subcommands.add_parser("parse", help="Benchmark parsing and generating an ast.AST") | ||||
| command_parse = subcommands.add_parser( | ||||
|     "parse", help="Benchmark parsing and generating an ast.AST" | ||||
| ) | ||||
| command_notree = subcommands.add_parser( | ||||
|     "notree", help="Benchmark parsing and dumping the tree" | ||||
| ) | ||||
| 
 | ||||
| 
 | ||||
| def benchmark(func): | ||||
|  | @ -62,7 +67,7 @@ def wrapper(*args): | |||
| 
 | ||||
| @benchmark | ||||
| def time_compile(source, parser): | ||||
|     if parser == "cpython": | ||||
|     if parser == "old": | ||||
|         return _peg_parser.compile_string( | ||||
|             source, | ||||
|             oldparser=True, | ||||
|  | @ -73,32 +78,40 @@ def time_compile(source, parser): | |||
| 
 | ||||
| @benchmark | ||||
| def time_parse(source, parser): | ||||
|     if parser == "cpython": | ||||
|     if parser == "old": | ||||
|         return _peg_parser.parse_string(source, oldparser=True) | ||||
|     else: | ||||
|         return _peg_parser.parse_string(source) | ||||
| 
 | ||||
| 
 | ||||
| @benchmark | ||||
| def time_notree(source, parser): | ||||
|     if parser == "old": | ||||
|         return _peg_parser.parse_string(source, oldparser=True, ast=False) | ||||
|     else: | ||||
|         return _peg_parser.parse_string(source, ast=False) | ||||
| 
 | ||||
| 
 | ||||
| def run_benchmark_xxl(subcommand, parser, source): | ||||
|     if subcommand == "compile": | ||||
|         time_compile(source, parser) | ||||
|     elif subcommand == "parse": | ||||
|         time_parse(source, parser) | ||||
|     elif subcommand == "notree": | ||||
|         time_notree(source, parser) | ||||
| 
 | ||||
| 
 | ||||
| def run_benchmark_stdlib(subcommand, parser): | ||||
|     modes = {"compile": 2, "parse": 1, "notree": 0} | ||||
|     for _ in range(3): | ||||
|         parse_directory( | ||||
|             "../../Lib", | ||||
|             "../../Grammar/python.gram", | ||||
|             "../../Grammar/Tokens", | ||||
|             verbose=False, | ||||
|             excluded_files=["*/bad*", "*/lib2to3/tests/data/*",], | ||||
|             skip_actions=False, | ||||
|             tree_arg=0, | ||||
|             short=True, | ||||
|             mode=2 if subcommand == "compile" else 1, | ||||
|             parser=parser, | ||||
|             mode=modes[subcommand], | ||||
|             oldparser=(parser == "old"), | ||||
|         ) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lysandros Nikolaou
						Lysandros Nikolaou