Created
May 3, 2013 19:00
-
-
Save metakermit/5512857 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": "knowledge.scipy.integrate.benchmark" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "from scipy import integrate\nimport numpy as np\nimport pandas as pd", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "x = np.abs(np.random.randn(10000))\nprint(x)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "[ 0.66290476 1.35351935 1.47110616 ..., 1.98089506 0.4121001\n 0.32761199]\n" | |
} | |
], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "%timeit integrate.trapz(x)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "10000 loops, best of 3: 72.2 \u00b5s per loop\n" | |
} | |
], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "ts = pd.Series(x, pd.date_range(start='2013-05-03', periods=len(x), freq='s'))\nprint(ts)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "2013-05-03 00:00:00 0.662905\n2013-05-03 00:00:01 1.353519\n2013-05-03 00:00:02 1.471106\n2013-05-03 00:00:03 0.636451\n2013-05-03 00:00:04 0.400131\n2013-05-03 00:00:05 0.438203\n2013-05-03 00:00:06 0.283670\n2013-05-03 00:00:07 1.390324\n2013-05-03 00:00:08 0.589401\n2013-05-03 00:00:09 0.698161\n2013-05-03 00:00:10 0.263194\n2013-05-03 00:00:11 2.247498\n2013-05-03 00:00:12 0.612423\n2013-05-03 00:00:13 0.033452\n2013-05-03 00:00:14 0.531537\n...\n2013-05-03 02:46:25 0.888961\n2013-05-03 02:46:26 0.617411\n2013-05-03 02:46:27 1.515751\n2013-05-03 02:46:28 0.682397\n2013-05-03 02:46:29 2.362538\n2013-05-03 02:46:30 0.314756\n2013-05-03 02:46:31 0.620458\n2013-05-03 02:46:32 1.009591\n2013-05-03 02:46:33 0.706764\n2013-05-03 02:46:34 0.279825\n2013-05-03 02:46:35 1.002564\n2013-05-03 02:46:36 0.210033\n2013-05-03 02:46:37 1.980895\n2013-05-03 02:46:38 0.412100\n2013-05-03 02:46:39 0.327612\nFreq: S, Length: 10000\n" | |
} | |
], | |
"prompt_number": 19 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Integrate\n==========" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "%timeit integrate.trapz(ts, ts.index.astype(np.int64) / 10**9)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "10 loops, best of 3: 58.4 ms per loop\n" | |
} | |
], | |
"prompt_number": 20 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment