{ "cells": [ { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "import math\n", "import numpy as np\n", "from numba import jit" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "@jit\n", "def is_prime_numba(n):\n", " if n % 2 == 0 or n % 3 == 0:\n", " return False\n", " k = 1\n", " limit = int(math.sqrt(n))\n", " while 6 * k - 1 <= limit or 6 * k + 1 <= limit:\n", " if n % (6 * k - 1) == 0 or n % (6 * k + 1) == 0:\n", " return False\n", " k += 1\n", " return True" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1 loop, best of 3: 5.22 s per loop\n" ] } ], "source": [ "%timeit is_prime_numba(2305843009213693951)" ] } ], "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.1" } }, "nbformat": 4, "nbformat_minor": 2 }