mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-24 04:21:15 +00:00
70 lines
1.4 KiB
Plaintext
70 lines
1.4 KiB
Plaintext
|
{
|
||
|
"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": {}
|
||
|
}
|
||
|
]
|
||
|
}
|