Mercurial > hg
changeset 33580:20436925e080 stable
run-tests: pre instantiate pygments objects
This speeds up run-tests.py diff output by 10x, which affects developer
experience significantly. As demonstrated by the following test:
```
#require pygments
$ for i in `seq 1 200`; do
> echo ' $ echo '$i >> test-a.t
> echo ' wrong' >> test-a.t
> done
$ cat > walltime.py <<EOF
> from __future__ import absolute_import, print_function
> import os, sys, time
> t1 = time.time()
> os.system(' '.join(sys.argv[1:]) + ' >/dev/null 2>/dev/null')
> t2 = time.time()
> print('%0.2f' % (t2 - t1))
> EOF
$ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=never $TESTTMP/test-a.t
0.24
Before this patch:
$ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=always $TESTTMP/test-a.t
2.46
After this patch:
$ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=always $TESTTMP/test-a.t
0.25
```
author | Jun Wu <quark@fb.com> |
---|---|
date | Fri, 21 Jul 2017 08:43:39 -0700 |
parents | 637267114513 |
children | e12c3049af8e |
files | tests/run-tests.py |
diffstat | 1 files changed, 5 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/run-tests.py Wed Jul 19 13:44:22 2017 -0400 +++ b/tests/run-tests.py Fri Jul 21 08:43:39 2017 -0700 @@ -96,6 +96,8 @@ import pygments.lexers as lexers import pygments.formatters as formatters pygmentspresent = True + difflexer = lexers.DiffLexer() + terminal256formatter = formatters.Terminal256Formatter() except ImportError: pass @@ -1651,10 +1653,9 @@ self.stream.write('\n') for line in lines: if self.color: - line = pygments.highlight( - line, - lexers.DiffLexer(), - formatters.Terminal256Formatter()) + line = pygments.highlight(line, + difflexer, + terminal256formatter) if PYTHON3: self.stream.flush() self.stream.buffer.write(line)