[MERGE][bug #297831] don't call chdir('')

John Arbash Meinel john at arbash-meinel.com
Wed Nov 19 21:08:38 GMT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marius Kruger wrote:
> 2008/11/19 John Arbash Meinel <john at arbash-meinel.com
> <mailto:john at arbash-meinel.com>>
> 
>     $ 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
> 
> ...
> 
> I'm interested to know how it compares with your initial alternative:
> $ TIMEIT -s 'x = ""' 'if len(x) == 0: pass'
> 
> regards
> marius


Interestingly, at least in python you suffer a full generic function
call. It is slightly faster than bool, but significantly slower than
either "if x" or "if x != ''":

$ TIMEIT -s 'x = "this/is/a/longer/path"' 'if len(x) == 0: pass'
10000000 loops, best of 3: 0.132 usec per loop
$ TIMEIT -s 'x = ""' 'if len(x) == 0: pass'
10000000 loops, best of 3: 0.129 usec per loop

I'm curious what would happen in pyrex, as it calls the PyObject_Length
function directly. But not curious enough to actually build everything
to test it right now. :)

John
=:_>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkkgFYACgkQJdeBCYSNAAOFWACfbptGwMTL/bjn03ZT3J7Edh08
SA0AnjG+c5B006bHCHUs3ruXXC+nViGi
=mrqe
-----END PGP SIGNATURE-----



More information about the bazaar mailing list