diff --git a/pycon2017_cffi.ipynb b/pycon2017_cffi.ipynb index a505a10..bd3668d 100644 --- a/pycon2017_cffi.ipynb +++ b/pycon2017_cffi.ipynb @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -104,7 +104,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 2, "metadata": { "collapsed": true, "nbpresent": { @@ -152,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 3, "metadata": { "collapsed": true, "nbpresent": { @@ -186,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 4, "metadata": { "collapsed": true, "nbpresent": { @@ -198,7 +198,7 @@ }, "outputs": [], "source": [ - "# This is the calculating function\n", + "# This is the calculating function in python\n", "\n", "def mandel(x, y, max_iters, value):\n", " \"\"\"\n", @@ -220,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 5, "metadata": { "nbpresent": { "id": "e5336db1-ebd6-4ddf-93fe-1de2f67af19a" @@ -234,7 +234,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "pure python required 6.69 secs\n" + "pure python required 5.23 secs\n" ] } ], @@ -255,7 +255,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 11, "metadata": { "nbpresent": { "id": "2477301c-828f-4c7a-9276-1536e4518ab6" @@ -1046,7 +1046,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -1059,7 +1059,8 @@ "source": [ "fig, ax = subplots(1)\n", "img = Image.open('python_numpy.png')\n", - "ax.imshow(img); ax.set_title('pure python, {:.2f} millisecs'.format(pure_python*1000));" + "ax.imshow(img); \n", + "ax.set_title('pure python, {:.2f} millisecs'.format(pure_python*1000));" ] }, { @@ -1073,7 +1074,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -1110,7 +1111,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 8, "metadata": { "nbpresent": { "id": "05edfb6e-ca49-470a-a1fd-19e36c908a7e" @@ -1155,7 +1156,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 9, "metadata": { "nbpresent": { "id": "728b3e91-ccb1-4ce4-8da1-3005580df8c7" @@ -1231,7 +1232,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 14, "metadata": { "nbpresent": { "id": "4546c856-db4f-4dce-95fc-7363a463a8d0" @@ -1242,9 +1243,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "create_fractal required 183 millisecs\n", - "\n", - "Pure python is 40.1 times slower than pure C\n" + "b'create_fractal required 201 millisecs\\n'\n", + "Pure python is 26.0 times slower than pure C\n" ] } ], @@ -1255,6 +1255,7 @@ "environ['LD_LIBRARY_PATH'] = environ.get('LD_LIBRARY_PATH', '') + ':'\n", "p = subprocess.Popen(['./main'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ)\n", "stdout, stderr = p.communicate()\n", + "stdout = str(stdout)\n", "print(stdout)\n", "pure_c = int(stdout.split(' ')[2])\n", "print('Pure python is {:.1f} times slower than pure C'.format(1000.0*pure_python/pure_c));" @@ -1262,7 +1263,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 15, "metadata": { "nbpresent": { "id": "21a2f51d-22e3-4957-b953-1001eef24e17" @@ -2050,7 +2051,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -2085,7 +2086,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 16, "metadata": { "collapsed": true }, @@ -2143,15 +2144,15 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "ctypes calling create_fractal required 204.99 millisecs\n", - "ctypes calling mandel required 3035.88 millisecs\n" + "ctypes calling create_fractal required 203.95 millisecs\n", + "ctypes calling mandel required 2604.29 millisecs\n" ] } ], @@ -2176,7 +2177,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -2959,7 +2960,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -2979,7 +2980,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -3033,8 +3034,10 @@ }, { "cell_type": "code", - "execution_count": 59, - "metadata": {}, + "execution_count": 20, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "# Initializing an image looks just like C. Note two things:\n", @@ -3051,15 +3054,15 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "cffi calling create_fractal required 188.93 millisecs\n", - "cffi calling mandel required 979.19 millisecs\n" + "cffi calling create_fractal required 199.04 millisecs\n", + "cffi calling mandel required 1058.79 millisecs\n" ] } ], @@ -3086,7 +3089,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -3869,7 +3872,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -3889,18 +3892,9 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 23, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The Cython extension is already loaded. To reload it, use:\n", - " %reload_ext Cython\n" - ] - } - ], + "outputs": [], "source": [ "%load_ext Cython" ] @@ -3919,7 +3913,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -3930,7 +3924,7 @@ "\n", "\n", " \n", - " Cython: _cython_magic_5d41d8394e294d84cc8fe88bb584ae40.pyx\n", + " Cython: _cython_magic_9c22eca2a6bd2d5b9af4661a58599210.pyx\n", " \n", "