blob: 3723f69645f77a78f721aa08591210e65fa6089d [file] [log] [blame]
Martin v. Löwis5e37bae2008-03-19 04:43:46 +00001#!/usr/bin/env python2.5
2"""
3This is a benchmarking script to test the speed of 2to3's pattern matching
4system. It's equivalent to "refactor.py -f all" for every Python module
5in sys.modules, but without engaging the actual transformations.
6"""
7
8__author__ = "Collin Winter <collinw at gmail.com>"
9
10# Python imports
11import os.path
12import sys
13from time import time
14
15# Test imports
16from support import adjust_path
17adjust_path()
18
19# Local imports
20from .. import refactor
21
22### Mock code for refactor.py and the fixers
23###############################################################################
24class Options:
25 def __init__(self, **kwargs):
26 for k, v in kwargs.items():
27 setattr(self, k, v)
28
29 self.verbose = False
Martin v. Löwisab41b372008-03-19 05:22:42 +000030
Martin v. Löwis5e37bae2008-03-19 04:43:46 +000031def dummy_transform(*args, **kwargs):
32 pass
Martin v. Löwisab41b372008-03-19 05:22:42 +000033
Martin v. Löwis5e37bae2008-03-19 04:43:46 +000034### Collect list of modules to match against
35###############################################################################
36files = []
37for mod in sys.modules.values():
38 if mod is None or not hasattr(mod, '__file__'):
39 continue
40 f = mod.__file__
41 if f.endswith('.pyc'):
42 f = f[:-1]
43 if f.endswith('.py'):
44 files.append(f)
45
46### Set up refactor and run the benchmark
47###############################################################################
48options = Options(fix=["all"], print_function=False, doctests_only=False)
49refactor = refactor.RefactoringTool(options)
50for fixer in refactor.fixers:
51 # We don't want them to actually fix the tree, just match against it.
52 fixer.transform = dummy_transform
53
54t = time()
55for f in files:
56 print "Matching", f
57 refactor.refactor_file(f)
58print "%d seconds to match %d files" % (time() - t, len(sys.modules))