-
-
Save ikura1/db74a868b5ba0c57870bfd64fed93af0 to your computer and use it in GitHub Desktop.
sqrt.ipynb
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "sqrt.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/ikura1/db74a868b5ba0c57870bfd64fed93af0/sqrt.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "wQBMHXTc_lVT", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"\n", | |
"## nの平方根どれが早い?\n", | |
"思った以上にやり方がある\n", | |
"\n", | |
"* n ** 0.5\n", | |
"* pow\n", | |
"* math\n", | |
"* numpy\n", | |
"* sympy\n", | |
"* scipy\n", | |
"\n", | |
"mathが一番早い" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "F8rvpo17QJRW", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "acf033d4-e326-4ea9-90b4-f2c8cd7b3797" | |
}, | |
"source": [ | |
"%shell python --version" | |
], | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Python 3.6.8\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 9 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "q96HZxueAhdn", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import math\n", | |
"import numpy as np\n", | |
"import sympy\n", | |
"import scipy\n", | |
"\n", | |
"n = 123456789" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ptR0zDU6_2Pe", | |
"colab_type": "code", | |
"outputId": "25f53be7-d604-46ce-fc5c-ec8d639f55c6", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"%%timeit -r 3 -n 1000000\n", | |
"n ** 0.5" | |
], | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"1000000 loops, best of 3: 147 ns per loop\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "x-tKrKPkD6QN", | |
"colab_type": "code", | |
"outputId": "7652533d-7390-421d-e802-dce7b8df5706", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"%%timeit -r 3 -n 1000000\n", | |
"pow(n, 0.5)" | |
], | |
"execution_count": 12, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"1000000 loops, best of 3: 212 ns per loop\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "TM-EMEWyBzQM", | |
"colab_type": "code", | |
"outputId": "da63b16c-4ab0-43a1-ce26-0dd4581e07a3", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"%%timeit -r 3 -n 1000000\n", | |
"math.sqrt(n)" | |
], | |
"execution_count": 13, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"1000000 loops, best of 3: 76.3 ns per loop\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "-Rnw5QtYEEv2", | |
"colab_type": "code", | |
"outputId": "b51168fa-6f2e-4ac0-9585-0816b6bf651a", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"%%timeit -r 3 -n 100000\n", | |
"np.sqrt(n)" | |
], | |
"execution_count": 14, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"100000 loops, best of 3: 964 ns per loop\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Y5A38C5JEGYD", | |
"colab_type": "code", | |
"outputId": "9f135ad8-dbe8-4e8b-c6f3-1e24ed27fffb", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"%%timeit -r 3 -n 1000000\n", | |
"sympy.sqrt(n)" | |
], | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"1000000 loops, best of 3: 1.21 µs per loop\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "LxsEyyFgEH5n", | |
"colab_type": "code", | |
"outputId": "9a5c61ea-f4da-4834-a5af-07bcbbe751cf", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
} | |
}, | |
"source": [ | |
"%%timeit -r 3 -n 1000000\n", | |
"scipy.sqrt(n)" | |
], | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"1000000 loops, best of 3: 7.73 µs per loop\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "NgxNlDkYn6CJ", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment