Slow tests

Harald Meland harald.meland at usit.uio.no
Thu Sep 17 21:04:13 BST 2009


[John Arbash Meinel]

> Robert Collins wrote:
>> On Thu, 2009-09-17 at 14:50 +1000, Martin Pool wrote:
>>> time grep "assert " bzrlib/**/*py takes 100ms on my laptop so there
>>> seems considerable room for improvement from 30000ms.
>> 
>> Yup. That was run on my desktop, which is still importing my netbeans
>> memory dump; its possble there was IO noise. Never-the-less, it did take
>> that long :).
>
> assert tests run slow because it compiles the AST and walks it, rather
> than just grepping the source code for 'assert'.

I've done a quick first improvement to this in
lp:~hmeland/bzr/bzr.faster-test-no-assert by doing a regexp search
using

        assert_re = re.compile(r'\bassert\b')

over the file text before doing any expensive AST stuff; this brings
that test down to ~3 seconds (from ~20) on my machine.

(I also replaced "''.join(text)" with just "text", as "text" should
already always be the full file text as returned by file.read().)

> I assumed that this was an explicit decision by Martin when he wrote the
> test, but yes, that is a very slow one.

I'm also experimenting with a more fancy regexp, something like

        assert_re = re.compile(r'(?:^|[:;])\s*assert\b', flags=re.MULTILINE)

but while that will bring the runtime down to ~780ms on my machine,
I'm not entirely confident that it will catch *all* ways of writing an
assert statement in Python syntax.

Should I go with the former or the latter?
-- 
Harald



More information about the bazaar mailing list