Last active
February 11, 2018 17:28
-
-
Save noklam/a0d020c17ce1715bf1d031b1cb8a9fa4 to your computer and use it in GitHub Desktop.
Demo_1.ipynb
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
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T11:30:30.864408Z", | |
"start_time": "2018-02-02T11:30:29.851479Z" | |
}, | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%load_ext Cython", | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T17:30:18.571919Z", | |
"start_time": "2018-02-02T17:30:18.554872Z" | |
}, | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def fib1(n):\n a, b = 0, 1\n while b < n:\n a, b = b, a + b ", | |
"execution_count": 56, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T17:30:18.609044Z", | |
"start_time": "2018-02-02T17:30:18.602039Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%time fib1(1000)", | |
"execution_count": 57, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Wall time: 0 ns\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T17:30:26.977195Z", | |
"start_time": "2018-02-02T17:30:18.638121Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%timeit fib1(1000)", | |
"execution_count": 58, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "1.01 µs ± 33.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T17:34:23.000667Z", | |
"start_time": "2018-02-02T17:34:22.997659Z" | |
}, | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def dummy(n):\n for i in range(int(1e7)):\n fib1(n)", | |
"execution_count": 73, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T17:34:30.272436Z", | |
"start_time": "2018-02-02T17:34:23.449730Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%prun dummy(50)", | |
"execution_count": 74, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": " " | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T17:38:06.050628Z", | |
"start_time": "2018-02-02T17:38:06.046619Z" | |
}, | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def fib1(n):\n a, b = 0, 1\n while b < n:\n a, b = b, a + b ", | |
"execution_count": 75, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T17:38:06.311078Z", | |
"start_time": "2018-02-02T17:38:06.303092Z" | |
}, | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%%cython\ndef fib2(n):\n a, b = 0, 1\n while b < n:\n a, b = b, a + b", | |
"execution_count": 76, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T17:38:13.731500Z", | |
"start_time": "2018-02-02T17:38:06.645751Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%timeit fib1(50)\n%timeit fib2(50)", | |
"execution_count": 77, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "582 ns ± 28 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n285 ns ± 13.2 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-02-04T17:25:43.783959Z", | |
"end_time": "2018-02-04T17:25:45.367955Z" | |
}, | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%%cython\ndef fib3(int n):\n cdef int b = 1\n cdef int a = 0\n cdef int t = 0\n while b < n:\n t = a\n a = b\n b = t + b", | |
"execution_count": 23, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-02-04T17:25:45.382500Z", | |
"end_time": "2018-02-04T17:25:49.359567Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%timeit fib3(50)", | |
"execution_count": 24, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "48.4 ns ± 1.33 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-02T11:33:17.141443Z", | |
"start_time": "2018-02-02T11:33:04.894168Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%timeit fib1(50)\n\n%timeit fib2(50)\n\n%timeit fib3(50)", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "627 ns ± 7.46 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n318 ns ± 3.51 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n55.5 ns ± 2.47 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)\n" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "# Heading" | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "## heading" | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "### heading" | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-02-04T10:09:32.022086Z", | |
"start_time": "2018-02-04T10:09:32.001030Z" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "!cd", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "D:\\Sync\\Courses\\fastai\\courses\\ml1\n" | |
} | |
] | |
} | |
], | |
"metadata": { | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/4f83950fe6d7edb62beb95d60dff766b" | |
}, | |
"gist": { | |
"id": "4f83950fe6d7edb62beb95d60dff766b", | |
"data": { | |
"description": "Demo_1.ipynb", | |
"public": true | |
} | |
}, | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.3" | |
}, | |
"varInspector": { | |
"cols": { | |
"lenName": 16, | |
"lenType": 16, | |
"lenVar": 40 | |
}, | |
"kernels_config": { | |
"python": { | |
"delete_cmd_postfix": "", | |
"delete_cmd_prefix": "del ", | |
"library": "var_list.py", | |
"varRefreshCmd": "print(var_dic_list())" | |
}, | |
"r": { | |
"delete_cmd_postfix": ") ", | |
"delete_cmd_prefix": "rm(", | |
"library": "var_list.r", | |
"varRefreshCmd": "cat(var_dic_list()) " | |
} | |
}, | |
"types_to_exclude": [ | |
"module", | |
"function", | |
"builtin_function_or_method", | |
"instance", | |
"_Feature" | |
], | |
"window_display": false | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment