Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64620
| Date | 2014-01-23 15:43 +0000 |
|---|---|
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Subject | Re: Case insensitive exists()? |
| References | <mailman.5853.1390438708.18130.python-list@python.org> <roy-7A7FAE.20082622012014@news.panix.com> <mailman.5855.1390439920.18130.python-list@python.org> <roy-1771A1.20270322012014@news.panix.com> <CACwCsY6Lq=x=XSc6Edqh+v0RH2Q-9t+2cgJ+xbsC+ADfsh90pA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5897.1390491833.18130.python-list@python.org> (permalink) |
On Wed, Jan 22, 2014 at 09:24:54PM -0700, Larry Martell wrote:
>
> I am writing something that is part of a django app, that based on
> some web entry from the user, I run a query, get back a list of files
> and have to go receive them and serve them up back to the browser. My
> script is all done and seem to be working, then today I was informed
> it was not serving up all the images. Debugging revealed that it was
> this case issue - I was matching with exists(). As I've said, coding a
> solution is easy, but I fear it will be too slow. Speed is important
> in web apps - users have high expectations. Guess I'll just have to
> try it and see.
How long does it actually take to serve a http request? I would expect it to
be orders of magnitudes slower than calling os.listdir on a directory
containing hundreds of files.
Here on my Linux system there are 2000+ files in /usr/bin. Calling os.listdir
takes 1.5 milliseconds (warm cache):
$ python -m timeit -s 'import os' 'os.listdir("/usr/bin")'
1000 loops, best of 3: 1.42 msec per loop
Converting those to upper case takes a further .5 milliseconds:
$ python -m timeit -s 'import os' 'map(str.upper, os.listdir("/usr/bin"))'
1000 loops, best of 3: 1.98 msec per loop
Checking a string against that list takes .05 milliseconds:
$ python -m timeit -s 'import os' \
'"WHICH" in map(str.upper, os.listdir("/usr/bin"))'
1000 loops, best of 3: 2.03 msec per loop
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Case insensitive exists()? Larry Martell <larry.martell@gmail.com> - 2014-01-22 17:58 -0700
Re: Case insensitive exists()? Roy Smith <roy@panix.com> - 2014-01-22 20:08 -0500
Re: Case insensitive exists()? Larry Martell <larry.martell@gmail.com> - 2014-01-22 18:18 -0700
Re: Case insensitive exists()? Roy Smith <roy@panix.com> - 2014-01-22 20:27 -0500
Re: Case insensitive exists()? Larry Martell <larry.martell@gmail.com> - 2014-01-22 21:24 -0700
Re: Case insensitive exists()? Chris Angelico <rosuav@gmail.com> - 2014-01-23 15:29 +1100
Re: Case insensitive exists()? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-01-23 15:43 +0000
Re: Case insensitive exists()? Larry Martell <larry.martell@gmail.com> - 2014-01-23 12:02 -0700
Re: Case insensitive exists()? Dan Sommers <dan@tombstonezero.net> - 2014-01-23 07:51 +0000
Re: Case insensitive exists()? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-23 12:06 +0000
Re: Case insensitive exists()? Grant Edwards <invalid@invalid.invalid> - 2014-01-23 14:58 +0000
csiph-web