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": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import datetime\n", | |
"\n", | |
"def time_it(func):\n", | |
" def timed(*args, **kwargs):\n", | |
" start = datetime.datetime.now()\n", | |
"\n", | |
" result = func(*args, **kwargs)\n", | |
"\n", | |
" end = datetime.datetime.now()\n", | |
"\n", | |
" print('running %s took %s' % (func.__name__,\n", | |
" end-start))\n", | |
" print('arguments used: %s %s' % (args, kwargs))\n", | |
" return timed\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import time\n", | |
"\n", | |
"@time_it\n", | |
"def wait_a_little(seconds):\n", | |
" time.sleep(seconds)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"running wait_a_little took 0:00:01.001179\n", | |
"arguments used: (1,) {}\n" | |
] | |
} | |
], | |
"source": [ | |
"wait_a_little(1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"running wait_a_little took 0:00:02.002741\n", | |
"arguments used: (2,) {}\n" | |
] | |
} | |
], | |
"source": [ | |
"wait_a_little(2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"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.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment