Skip to content

Instantly share code, notes, and snippets.

@saghul
Created September 7, 2010 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saghul/569053 to your computer and use it in GitHub Desktop.
Save saghul/569053 to your computer and use it in GitHub Desktop.
saghul@hal:~$ ipython
Python 2.6.6rc1+ (r266rc1:83691, Aug 5 2010, 17:07:04)
Type "copyright", "credits" or "license" for more information.
IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import random
In [2]: l = [random.randint(0, 100) for n in xrange(0,100)]
In [3]: s = set(l)
In [4]: def sum_items(iter):
...: num = 0
...: for i in iter:
...: num += i
...:
...:
In [5]: %timeit sum_items(l)
100000 loops, best of 3: 8.99 us per loop
In [6]: %timeit sum_items(s)
100000 loops, best of 3: 6.87 us per loop
In [7]: %timeit 69 in l
1000000 loops, best of 3: 1.99 us per loop
In [8]: %timeit 69 in s
10000000 loops, best of 3: 140 ns per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment