Created
July 19, 2014 17:58
-
-
Save yuyichao/7f7a512eaaaa33236543 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
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:5e0db451a22d1877147750b3d5fad4d0d094cd5921d48387d5ea3d64ca8f0d19" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"def func(i):\n", | |
" return i\n", | |
"\n", | |
"def run_loop(n):\n", | |
" for i in range(n, -1, -1):\n", | |
" if func(i) == 0:\n", | |
" break" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# cpython3\n", | |
"%timeit run_loop(10)\n", | |
"%timeit run_loop(100)\n", | |
"%timeit run_loop(1000)\n", | |
"%timeit run_loop(10000)\n", | |
"%timeit run_loop(100000)\n", | |
"%timeit run_loop(1000000)\n", | |
"%timeit run_loop(10000000)\n", | |
"%timeit run_loop(100000000)\n", | |
"%timeit run_loop(1000000000)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"100000 loops, best of 3: 2.08 \u00b5s per loop\n", | |
"100000 loops, best of 3: 14.5 \u00b5s per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"10000 loops, best of 3: 155 \u00b5s per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"1000 loops, best of 3: 1.58 ms per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"100 loops, best of 3: 15.9 ms per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"10 loops, best of 3: 158 ms per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"1 loops, best of 3: 1.59 s per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"1 loops, best of 3: 15.7 s per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"1 loops, best of 3: 2min 35s per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# pypy\n", | |
"%timeit run_loop(10)\n", | |
"%timeit run_loop(100)\n", | |
"%timeit run_loop(1000)\n", | |
"%timeit run_loop(10000)\n", | |
"%timeit run_loop(100000)\n", | |
"%timeit run_loop(1000000)\n", | |
"%timeit run_loop(10000000)\n", | |
"%timeit run_loop(100000000)\n", | |
"%timeit run_loop(1000000000)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"100000000 loops, best of 3: 2.37 ns per loop\n", | |
"100000000 loops, best of 3: 2.39 ns per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"100000000 loops, best of 3: 2.44 ns per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"100000000 loops, best of 3: 2.3 ns per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"100000000 loops, best of 3: 2.42 ns per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"100000000 loops, best of 3: 2.42 ns per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"100000000 loops, best of 3: 2.45 ns per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"100000000 loops, best of 3: 2.44 ns per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"100000000 loops, best of 3: 2.36 ns per loop" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 3 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment