pyzipcode icon indicating copy to clipboard operation
pyzipcode copied to clipboard

Speed up the `find_zip` method + support for exact queries and limits

Open wojcikstefan opened this issue 12 years ago • 0 comments

Master branch:

In [3]: %timeit pyzipcode.ZipCodeDatabase().find_zip(state='CA')
10 loops, best of 3: 32 ms per loop

This PR:

In [2]: %timeit pyzipcode.ZipCodeDatabase().find_zip(state='CA')
10 loops, best of 3: 25.6 ms per loop

In [3]: %timeit pyzipcode.ZipCodeDatabase().find_zip(state='CA', exact=True)
100 loops, best of 3: 14.3 ms per loop

In [4]: %timeit pyzipcode.ZipCodeDatabase().find_zip(state='CA', exact=True, limit=1)
1000 loops, best of 3: 273 us per loop

The code is a bit less readable, but the performance gains are significant, especially if you don't need all the zip codes for a given city/state (hence the limit) and you're searching for an exact match.

wojcikstefan avatar Sep 19 '13 21:09 wojcikstefan