mirror of
https://github.com/rasbt/python_reference.git
synced 2025-01-18 15:27:09 +00:00
row slice benchmark
This commit is contained in:
parent
cabe3a8c55
commit
43171df6ed
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "",
|
"name": "",
|
||||||
"signature": "sha256:8294645ddf3a6997a4764ca0bb61458953a6e579d858ecbf59e69882af05d0df"
|
"signature": "sha256:08918c81301f699d85bfad155946f6e0102ce07bb31796cb9bdda23ffb2e22a6"
|
||||||
},
|
},
|
||||||
"nbformat": 3,
|
"nbformat": 3,
|
||||||
"nbformat_minor": 0,
|
"nbformat_minor": 0,
|
||||||
|
@ -1486,6 +1486,8 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., A[:,0:1]\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method2(A):\n",
|
"def colvec_method2(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = A[:,idx:idx+1]\n",
|
" colvec = A[:,idx:idx+1]\n",
|
||||||
|
@ -1500,9 +1502,11 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., A[:,0].reshape(-1,1)\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method3(A):\n",
|
"def colvec_method3(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = A[:,idx].reshape(A.shape[0],1)\n",
|
" colvec = A[:,idx].reshape(-1,1)\n",
|
||||||
" yield colvec"
|
" yield colvec"
|
||||||
],
|
],
|
||||||
"language": "python",
|
"language": "python",
|
||||||
|
@ -1514,6 +1518,8 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., np.vstack(A[:,0]\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method4(A):\n",
|
"def colvec_method4(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = np.vstack(A[:,idx])\n",
|
" colvec = np.vstack(A[:,idx])\n",
|
||||||
|
@ -1528,6 +1534,8 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., np.row_stack(A[:,0])\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method5(A):\n",
|
"def colvec_method5(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = np.row_stack(A[:,idx])\n",
|
" colvec = np.row_stack(A[:,idx])\n",
|
||||||
|
@ -1542,6 +1550,8 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., np.column_stack((A[:,0],))\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method6(A):\n",
|
"def colvec_method6(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = np.column_stack((A[:,idx],))\n",
|
" colvec = np.column_stack((A[:,idx],))\n",
|
||||||
|
@ -1552,6 +1562,22 @@
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"prompt_number": 74
|
"prompt_number": 74
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"collapsed": false,
|
||||||
|
"input": [
|
||||||
|
"# 1st column, e.g., A[:,[0]]\n",
|
||||||
|
"\n",
|
||||||
|
"def colvec_method7(A):\n",
|
||||||
|
" for idx in range(A.shape[1]):\n",
|
||||||
|
" colvec = A[:,[idx]]\n",
|
||||||
|
" yield colvec"
|
||||||
|
],
|
||||||
|
"language": "python",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"prompt_number": 89
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
|
@ -1576,7 +1602,8 @@
|
||||||
"for method in [\n",
|
"for method in [\n",
|
||||||
" colvec_method1, colvec_method2, \n",
|
" colvec_method1, colvec_method2, \n",
|
||||||
" colvec_method3, colvec_method4, \n",
|
" colvec_method3, colvec_method4, \n",
|
||||||
" colvec_method5, colvec_method6]:\n",
|
" colvec_method5, colvec_method6,\n",
|
||||||
|
" colvec_method7]:\n",
|
||||||
" print('\\nTest:', method.__name__)\n",
|
" print('\\nTest:', method.__name__)\n",
|
||||||
" %timeit test_method(colvec_method2, A)"
|
" %timeit test_method(colvec_method2, A)"
|
||||||
],
|
],
|
||||||
|
@ -1589,7 +1616,7 @@
|
||||||
"text": [
|
"text": [
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method1\n",
|
"Test: colvec_method1\n",
|
||||||
"100000 loops, best of 3: 17.7 \u00b5s per loop"
|
"100000 loops, best of 3: 16.6 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1599,7 +1626,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method2\n",
|
"Test: colvec_method2\n",
|
||||||
"10000 loops, best of 3: 16.4 \u00b5s per loop"
|
"10000 loops, best of 3: 16.1 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1609,7 +1636,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method3\n",
|
"Test: colvec_method3\n",
|
||||||
"100000 loops, best of 3: 17.3 \u00b5s per loop"
|
"100000 loops, best of 3: 16.2 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1619,7 +1646,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method4\n",
|
"Test: colvec_method4\n",
|
||||||
"10000 loops, best of 3: 16.4 \u00b5s per loop"
|
"100000 loops, best of 3: 16.4 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1629,7 +1656,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method5\n",
|
"Test: colvec_method5\n",
|
||||||
"100000 loops, best of 3: 17.1 \u00b5s per loop"
|
"100000 loops, best of 3: 16.2 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1639,7 +1666,17 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method6\n",
|
"Test: colvec_method6\n",
|
||||||
"100000 loops, best of 3: 16.6 \u00b5s per loop"
|
"100000 loops, best of 3: 16.8 \u00b5s per loop"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"output_type": "stream",
|
||||||
|
"stream": "stdout",
|
||||||
|
"text": [
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Test: colvec_method7\n",
|
||||||
|
"100000 loops, best of 3: 16.3 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1650,7 +1687,7 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"prompt_number": 86
|
"prompt_number": 91
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "",
|
"name": "",
|
||||||
"signature": "sha256:8294645ddf3a6997a4764ca0bb61458953a6e579d858ecbf59e69882af05d0df"
|
"signature": "sha256:08918c81301f699d85bfad155946f6e0102ce07bb31796cb9bdda23ffb2e22a6"
|
||||||
},
|
},
|
||||||
"nbformat": 3,
|
"nbformat": 3,
|
||||||
"nbformat_minor": 0,
|
"nbformat_minor": 0,
|
||||||
|
@ -1486,6 +1486,8 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., A[:,0:1]\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method2(A):\n",
|
"def colvec_method2(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = A[:,idx:idx+1]\n",
|
" colvec = A[:,idx:idx+1]\n",
|
||||||
|
@ -1500,9 +1502,11 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., A[:,0].reshape(-1,1)\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method3(A):\n",
|
"def colvec_method3(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = A[:,idx].reshape(A.shape[0],1)\n",
|
" colvec = A[:,idx].reshape(-1,1)\n",
|
||||||
" yield colvec"
|
" yield colvec"
|
||||||
],
|
],
|
||||||
"language": "python",
|
"language": "python",
|
||||||
|
@ -1514,6 +1518,8 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., np.vstack(A[:,0]\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method4(A):\n",
|
"def colvec_method4(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = np.vstack(A[:,idx])\n",
|
" colvec = np.vstack(A[:,idx])\n",
|
||||||
|
@ -1528,6 +1534,8 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., np.row_stack(A[:,0])\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method5(A):\n",
|
"def colvec_method5(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = np.row_stack(A[:,idx])\n",
|
" colvec = np.row_stack(A[:,idx])\n",
|
||||||
|
@ -1542,6 +1550,8 @@
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"input": [
|
"input": [
|
||||||
|
"# 1st column, e.g., np.column_stack((A[:,0],))\n",
|
||||||
|
"\n",
|
||||||
"def colvec_method6(A):\n",
|
"def colvec_method6(A):\n",
|
||||||
" for idx in range(A.shape[1]):\n",
|
" for idx in range(A.shape[1]):\n",
|
||||||
" colvec = np.column_stack((A[:,idx],))\n",
|
" colvec = np.column_stack((A[:,idx],))\n",
|
||||||
|
@ -1552,6 +1562,22 @@
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"prompt_number": 74
|
"prompt_number": 74
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"collapsed": false,
|
||||||
|
"input": [
|
||||||
|
"# 1st column, e.g., A[:,[0]]\n",
|
||||||
|
"\n",
|
||||||
|
"def colvec_method7(A):\n",
|
||||||
|
" for idx in range(A.shape[1]):\n",
|
||||||
|
" colvec = A[:,[idx]]\n",
|
||||||
|
" yield colvec"
|
||||||
|
],
|
||||||
|
"language": "python",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"prompt_number": 89
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
|
@ -1576,7 +1602,8 @@
|
||||||
"for method in [\n",
|
"for method in [\n",
|
||||||
" colvec_method1, colvec_method2, \n",
|
" colvec_method1, colvec_method2, \n",
|
||||||
" colvec_method3, colvec_method4, \n",
|
" colvec_method3, colvec_method4, \n",
|
||||||
" colvec_method5, colvec_method6]:\n",
|
" colvec_method5, colvec_method6,\n",
|
||||||
|
" colvec_method7]:\n",
|
||||||
" print('\\nTest:', method.__name__)\n",
|
" print('\\nTest:', method.__name__)\n",
|
||||||
" %timeit test_method(colvec_method2, A)"
|
" %timeit test_method(colvec_method2, A)"
|
||||||
],
|
],
|
||||||
|
@ -1589,7 +1616,7 @@
|
||||||
"text": [
|
"text": [
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method1\n",
|
"Test: colvec_method1\n",
|
||||||
"100000 loops, best of 3: 17.7 \u00b5s per loop"
|
"100000 loops, best of 3: 16.6 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1599,7 +1626,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method2\n",
|
"Test: colvec_method2\n",
|
||||||
"10000 loops, best of 3: 16.4 \u00b5s per loop"
|
"10000 loops, best of 3: 16.1 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1609,7 +1636,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method3\n",
|
"Test: colvec_method3\n",
|
||||||
"100000 loops, best of 3: 17.3 \u00b5s per loop"
|
"100000 loops, best of 3: 16.2 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1619,7 +1646,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method4\n",
|
"Test: colvec_method4\n",
|
||||||
"10000 loops, best of 3: 16.4 \u00b5s per loop"
|
"100000 loops, best of 3: 16.4 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1629,7 +1656,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method5\n",
|
"Test: colvec_method5\n",
|
||||||
"100000 loops, best of 3: 17.1 \u00b5s per loop"
|
"100000 loops, best of 3: 16.2 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1639,7 +1666,17 @@
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test: colvec_method6\n",
|
"Test: colvec_method6\n",
|
||||||
"100000 loops, best of 3: 16.6 \u00b5s per loop"
|
"100000 loops, best of 3: 16.8 \u00b5s per loop"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"output_type": "stream",
|
||||||
|
"stream": "stdout",
|
||||||
|
"text": [
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Test: colvec_method7\n",
|
||||||
|
"100000 loops, best of 3: 16.3 \u00b5s per loop"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1650,7 +1687,7 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"prompt_number": 86
|
"prompt_number": 91
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user