Created
September 7, 2010 20:39
-
-
Save saghul/569053 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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