mirror of
https://github.com/rasbt/python_reference.git
synced 2025-02-21 15:52:10 +00:00
ipynb for timeit
This commit is contained in:
parent
e0f29b6354
commit
b1590e5db0
70
timeit_test.ipynb
Normal file
70
timeit_test.ipynb
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
{
|
||||||
|
"metadata": {
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
"nbformat": 3,
|
||||||
|
"nbformat_minor": 0,
|
||||||
|
"worksheets": [
|
||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"collapsed": false,
|
||||||
|
"input": [
|
||||||
|
"import timeit\n",
|
||||||
|
"\n",
|
||||||
|
"def test_format():\n",
|
||||||
|
" return ['{}'.format(i) for i in range(1000000)]\n",
|
||||||
|
"\n",
|
||||||
|
"def test_binaryop():\n",
|
||||||
|
" return ['%s' %i for i in range(1000000)]\n",
|
||||||
|
"\n",
|
||||||
|
"%timeit test_format()\n",
|
||||||
|
"%timeit test_binaryop()\n",
|
||||||
|
"\n",
|
||||||
|
"#print('{}: {}\\n{}: {}'.format('format()', format_res, '%s', binaryop_res))\n",
|
||||||
|
"\n",
|
||||||
|
"################################\n",
|
||||||
|
"# On my machine\n",
|
||||||
|
"################################\n",
|
||||||
|
"#\n",
|
||||||
|
"# Python 3.4.0\n",
|
||||||
|
"# MacOS X 10.9.2\n",
|
||||||
|
"# 2.5 GHz Intel Core i5\n",
|
||||||
|
"# 4 GB 1600 Mhz DDR3\n",
|
||||||
|
"#\n"
|
||||||
|
],
|
||||||
|
"language": "python",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"output_type": "stream",
|
||||||
|
"stream": "stdout",
|
||||||
|
"text": [
|
||||||
|
"1 loops, best of 3: 400 ms per loop\n",
|
||||||
|
"1 loops, best of 3: 241 ms per loop"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"output_type": "stream",
|
||||||
|
"stream": "stdout",
|
||||||
|
"text": [
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"prompt_number": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"collapsed": false,
|
||||||
|
"input": [],
|
||||||
|
"language": "python",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user