Created
March 12, 2017 12:23
-
-
Save isRuslan/70bcca0ec2fc20a24c55131f24ba6259 to your computer and use it in GitHub Desktop.
fib bench
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": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## fibonacci benchmark" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"%matplotlib inline\n", | |
"import time\n", | |
"from matplotlib import pyplot as plt" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"21" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"def fib(n):\n", | |
" return n if n <= 1 else fib(n - 1) + fib(n - 2)\n", | |
"fib(8)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"21" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"def fib_iter(n):\n", | |
" assert n >= 0\n", | |
" a, b = 0, 1\n", | |
" for _ in range(n - 1):\n", | |
" a, b = b, a + b\n", | |
" return b\n", | |
"fib_iter(8)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"21" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from functools import lru_cache\n", | |
"\n", | |
"fib_cached = lru_cache()(fib)\n", | |
"fib_cached(8)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Реализуем функцию `bech` для замера времени работы:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"1.0889998520724475e-06\n", | |
"1.1629999789875e-05\n" | |
] | |
} | |
], | |
"source": [ | |
"def bech(f, *args, iter=100):\n", | |
" acc = float(\"inf\")\n", | |
" for _ in range(iter):\n", | |
" start = time.perf_counter()\n", | |
" f(*args)\n", | |
" end = time.perf_counter()\n", | |
" acc = min(acc, end - start)\n", | |
" return acc\n", | |
"\n", | |
"print(bech(fib_iter, 8))\n", | |
"print(bech(fib, 8))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Построим график зависимости времени от входного аргумента:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAD8CAYAAABpcuN4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt4VfWd7/H3NzcCJNwhIAEBCUJUREzx3hPGVi5e6GXq\n2HamWJ3jwxk9nfY8baWPc/HMM06ZmU471ao5zoxTnbZqW0sLFm90jK2liKgJyE0TRBIIAYK5Abnt\n/Tt/7BXchJ2dnezsvfZOPq/n2c9el99vre9a2awv67cuP3POISIi0psMvwMQEZHUpkQhIiJRKVGI\niEhUShQiIhKVEoWIiESlRCEiIlEpUYiISFRKFCIiEpUShYiIRJXldwCDYdKkSW7WrFkDrn/y5ElG\njx49eAENMsUXH8UXH8UXn1SO78033zzunJvcZ0HnXNp/Lr/8chePV155Ja76iab44qP44qP44pPK\n8QHbXQz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GNwHZZjYpWfE55w5530eB9YRO78P5uv88\nK4C3nHP1PWf4vf/C1Hc3yXnfRyOU8fu3eDtwE/BFL5mdI4bfQ0I45+qdcwHnXBD4t17W6/f+ywI+\nAzzTWxm/9t9ADZdE8QZQZGazvf913gZs6FFmA/Al7+6dK4GmsCaChPLaM/8D2OOc+24vZaZ65TCz\nJYT+dg1Jim+0meV3DxO64PlOj2K+7b8wvf4vzs/918MGYLU3vBr4VYQysfxeE8LMlgPfBG5xzp3q\npUwsv4dExRd+3evTvazXt/3n+QSw1zlXG2mmn/tvwPy+mp6sD6G7ct4ldDfEfd60NcAab9iAh735\nO4GSJMZ2LaEmiB1AhfdZ2SO+e4BdhO7g2ApcncT45njrrfRiSKn9561/NKED/9iwab7uP0JJqw7o\nJNROficwEfgN8B6wGZjglT0P2BTt95qk+KoIte93/w7LesbX2+8hSfH9l/f72kHo4D8tlfafN/2H\n3b+7sLJJ33+D+dGT2SIiEtVwaXoSEZEBUqIQEZGolChERCQqJQoREYlKiUJERKJSohARkaiUKERE\nJColChERier/A1TpnSE9scp6AAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x119f630b8>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"def compare(fs, args):\n", | |
" for f in fs:\n", | |
" plt.plot(args, [bech(f, arg) for arg in args], label=f.__name__)\n", | |
" plt.legend()\n", | |
" plt.grid(True) \n", | |
"\n", | |
"compare([fib, fib_iter], list(range(20))) " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Видим линейный рост `fib_iter` против экспоненциального `fib`" | |
] | |
}, | |
{ | |
"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.6.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment