{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-08-25T17:18:17.687180Z",
     "iopub.status.busy": "2020-08-25T17:18:17.686825Z",
     "iopub.status.idle": "2020-08-25T17:18:18.209918Z",
     "shell.execute_reply": "2020-08-25T17:18:18.208754Z",
     "shell.execute_reply.started": "2020-08-25T17:18:17.687126Z"
    }
   },
   "outputs": [],
   "source": [
    "from numba import jit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-08-25T17:18:18.211527Z",
     "iopub.status.busy": "2020-08-25T17:18:18.211326Z",
     "iopub.status.idle": "2020-08-25T17:18:18.215972Z",
     "shell.execute_reply": "2020-08-25T17:18:18.215023Z",
     "shell.execute_reply.started": "2020-08-25T17:18:18.211494Z"
    }
   },
   "outputs": [],
   "source": [
    "def fib(n):\n",
    "    a, b = 1, 1\n",
    "    for i in range(n):\n",
    "        a, b = a+b, a\n",
    "\n",
    "    return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-08-25T17:18:18.217980Z",
     "iopub.status.busy": "2020-08-25T17:18:18.217664Z",
     "iopub.status.idle": "2020-08-25T17:18:18.222376Z",
     "shell.execute_reply": "2020-08-25T17:18:18.221333Z",
     "shell.execute_reply.started": "2020-08-25T17:18:18.217925Z"
    }
   },
   "outputs": [],
   "source": [
    "N = int(10e4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-08-25T17:18:18.224204Z",
     "iopub.status.busy": "2020-08-25T17:18:18.223929Z",
     "iopub.status.idle": "2020-08-25T17:18:26.479459Z",
     "shell.execute_reply": "2020-08-25T17:18:26.478712Z",
     "shell.execute_reply.started": "2020-08-25T17:18:18.224146Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "101 ms ± 837 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit fib(N)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-08-25T17:18:26.481652Z",
     "iopub.status.busy": "2020-08-25T17:18:26.481341Z",
     "iopub.status.idle": "2020-08-25T17:18:26.485534Z",
     "shell.execute_reply": "2020-08-25T17:18:26.484478Z",
     "shell.execute_reply.started": "2020-08-25T17:18:26.481570Z"
    }
   },
   "outputs": [],
   "source": [
    "fib_jit = jit(fib)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2020-08-25T17:18:26.486818Z",
     "iopub.status.busy": "2020-08-25T17:18:26.486659Z",
     "iopub.status.idle": "2020-08-25T17:18:28.675857Z",
     "shell.execute_reply": "2020-08-25T17:18:28.675209Z",
     "shell.execute_reply.started": "2020-08-25T17:18:26.486792Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24.8 µs ± 693 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit fib_jit(N)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "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.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}