From 43171df6edf76aa8be304e54a82e8a34d2a8955d Mon Sep 17 00:00:00 2001 From: rasbt Date: Sat, 26 Apr 2014 14:47:03 -0400 Subject: [PATCH] row slice benchmark --- .../timeit_tests-checkpoint.ipynb | 57 +++++++++++++++---- benchmarks/timeit_tests.ipynb | 57 +++++++++++++++---- 2 files changed, 94 insertions(+), 20 deletions(-) diff --git a/.ipynb_checkpoints/timeit_tests-checkpoint.ipynb b/.ipynb_checkpoints/timeit_tests-checkpoint.ipynb index 8afaa8c..59f4d7f 100644 --- a/.ipynb_checkpoints/timeit_tests-checkpoint.ipynb +++ b/.ipynb_checkpoints/timeit_tests-checkpoint.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:8294645ddf3a6997a4764ca0bb61458953a6e579d858ecbf59e69882af05d0df" + "signature": "sha256:08918c81301f699d85bfad155946f6e0102ce07bb31796cb9bdda23ffb2e22a6" }, "nbformat": 3, "nbformat_minor": 0, @@ -1486,6 +1486,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., A[:,0:1]\n", + "\n", "def colvec_method2(A):\n", " for idx in range(A.shape[1]):\n", " colvec = A[:,idx:idx+1]\n", @@ -1500,9 +1502,11 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., A[:,0].reshape(-1,1)\n", + "\n", "def colvec_method3(A):\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" ], "language": "python", @@ -1514,6 +1518,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., np.vstack(A[:,0]\n", + "\n", "def colvec_method4(A):\n", " for idx in range(A.shape[1]):\n", " colvec = np.vstack(A[:,idx])\n", @@ -1528,6 +1534,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., np.row_stack(A[:,0])\n", + "\n", "def colvec_method5(A):\n", " for idx in range(A.shape[1]):\n", " colvec = np.row_stack(A[:,idx])\n", @@ -1542,6 +1550,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., np.column_stack((A[:,0],))\n", + "\n", "def colvec_method6(A):\n", " for idx in range(A.shape[1]):\n", " colvec = np.column_stack((A[:,idx],))\n", @@ -1552,6 +1562,22 @@ "outputs": [], "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", "collapsed": false, @@ -1576,7 +1602,8 @@ "for method in [\n", " colvec_method1, colvec_method2, \n", " colvec_method3, colvec_method4, \n", - " colvec_method5, colvec_method6]:\n", + " colvec_method5, colvec_method6,\n", + " colvec_method7]:\n", " print('\\nTest:', method.__name__)\n", " %timeit test_method(colvec_method2, A)" ], @@ -1589,7 +1616,7 @@ "text": [ "\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", "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", "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", "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", "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", "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", diff --git a/benchmarks/timeit_tests.ipynb b/benchmarks/timeit_tests.ipynb index 8afaa8c..59f4d7f 100644 --- a/benchmarks/timeit_tests.ipynb +++ b/benchmarks/timeit_tests.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:8294645ddf3a6997a4764ca0bb61458953a6e579d858ecbf59e69882af05d0df" + "signature": "sha256:08918c81301f699d85bfad155946f6e0102ce07bb31796cb9bdda23ffb2e22a6" }, "nbformat": 3, "nbformat_minor": 0, @@ -1486,6 +1486,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., A[:,0:1]\n", + "\n", "def colvec_method2(A):\n", " for idx in range(A.shape[1]):\n", " colvec = A[:,idx:idx+1]\n", @@ -1500,9 +1502,11 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., A[:,0].reshape(-1,1)\n", + "\n", "def colvec_method3(A):\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" ], "language": "python", @@ -1514,6 +1518,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., np.vstack(A[:,0]\n", + "\n", "def colvec_method4(A):\n", " for idx in range(A.shape[1]):\n", " colvec = np.vstack(A[:,idx])\n", @@ -1528,6 +1534,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., np.row_stack(A[:,0])\n", + "\n", "def colvec_method5(A):\n", " for idx in range(A.shape[1]):\n", " colvec = np.row_stack(A[:,idx])\n", @@ -1542,6 +1550,8 @@ "cell_type": "code", "collapsed": false, "input": [ + "# 1st column, e.g., np.column_stack((A[:,0],))\n", + "\n", "def colvec_method6(A):\n", " for idx in range(A.shape[1]):\n", " colvec = np.column_stack((A[:,idx],))\n", @@ -1552,6 +1562,22 @@ "outputs": [], "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", "collapsed": false, @@ -1576,7 +1602,8 @@ "for method in [\n", " colvec_method1, colvec_method2, \n", " colvec_method3, colvec_method4, \n", - " colvec_method5, colvec_method6]:\n", + " colvec_method5, colvec_method6,\n", + " colvec_method7]:\n", " print('\\nTest:', method.__name__)\n", " %timeit test_method(colvec_method2, A)" ], @@ -1589,7 +1616,7 @@ "text": [ "\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", "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", "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", "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", "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", "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",