[MERGE][bug #297831] don't call chdir('')
John Arbash Meinel
john at arbash-meinel.com
Wed Nov 19 20:47:29 GMT 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Aaron Bentley wrote:
> John Arbash Meinel wrote:
>> Aaron Bentley wrote:
>>> Aaron Bentley has voted tweak.
>>> Status is now: Conditionally approved
>>> Comment:
>>> Please change the test to if path != "" and -1 == chdir(path)
>>> For details, see:
>>> http://bundlebuggy.aaronbentley.com/project/bzr/request/%3C49244692.4050507%40arbash-meinel.com%3E
>>> Project: Bazaar
>>
>>
>> So I actually disagree with this, as "if path" can be translated into a
>> very cheap "PyObject_True(path)" call, rather than having to create a
>> temporary string object for "", and then call PyObject_Compare(path,
>> tmp_obj).
>
> If you can demonstrate that this has a significant impact on
> performance, I'll let it in as-is.
>
> Aaron
>
$ TIMEIT -s 'x = ""' 'if x != "": pass'
10000000 loops, best of 3: 0.0675 usec per loop
and
$ TIMEIT -s 'x = "this/is/a/longer/path"' 'if x != "": pass'
10000000 loops, best of 3: 0.0631 usec per loop
versus
$ TIMEIT -s 'x = ""' 'if x: pass'
10000000 loops, best of 3: 0.0465 usec per loop
and
$ TIMEIT -s 'x = "this/is/a/longer/path"' 'if x: pass'
10000000 loops, best of 3: 0.0421 usec per loop
Note that this is dramatically different than using bool()
$ TIMEIT -s 'x = ""' 'if bool(x): pass'
1000000 loops, best of 3: 0.266 usec per loop
$ TIMEIT -s 'x = "this/is/a/longer/path"' 'if bool(x): pass'
1000000 loops, best of 3: 0.264 usec per loop
So doing a comparison takes 3:2 times as long as doing the IsTrue test.
And using bool() is about 4 times longer than either.
Would the .02usec per loop have a measurable impact on the overall time
of "bzr status". I would guess it is lost mostly in the noise. Still
1) it *is* faster
2) I find the code just as easy to read, others may disagree.
3) You're version of the check doesn't really protect anything, as it
just means we end up calling PyStringAsString on an empty list/None/etc.
(though it would have long since failed in the calling code, but
assuming it got that far...)
I can do it just to get it done, but I feel like this is a personal
style issue, and as we haven't standardized on either way there isn't
much of a reason to pick one over the other.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkkke2EACgkQJdeBCYSNAANC3ACfbeXq7asbpBDanXcddjID9nU+
KIIAoIjAHgwwKS5r2qU12WQDR4pRBTpD
=qEa9
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list