[PATCH 2 of 3] dirstate: test normalize is not None instead of using a no-op lambda

Siddharth Agarwal sid0 at fb.com
Mon Dec 3 18:32:25 CST 2012


On 12/03/2012 02:33 PM, Matt Mackall wrote:
> $ python -m timeit -s 'n = None' -c 'if n: pass'
> 100000000 loops, best of 3: 0.0143 usec per loop
> $ python -m timeit -s 'n = None' -c 'if n is not None: pass'
> 100000000 loops, best of 3: 0.0178 usec per loop

Switching to "if normalize:" didn't bring about a measurable difference 
to perfstatus -u. The lambda variant is relatively a lot slower, so 
there's no surprise that I saw a perf difference there. On my install:

$ python -m timeit -s 'n = lambda x, y, z: x' -c 'n(True, True, True)'
1000000 loops, best of 3: 0.22 usec per loop
$ python -m timeit -s 'n = lambda x, y, z: x' -c 'n(None, None, None)'
10000000 loops, best of 3: 0.142 usec per loop
$ python -m timeit -s 'n = None' -c 'if n is not None: pass'
10000000 loops, best of 3: 0.044 usec per loop
$ python -m timeit -s 'n = None' -c 'if n: pass'
10000000 loops, best of 3: 0.036 usec per loop

However, if you think it's better clarity-wise, I can resend the patch 
with the change.


More information about the Mercurial-devel mailing list