-
-
Save ttsugriy/635628f829e1a84abdffec272d083ed7 to your computer and use it in GitHub Desktop.
Untitled2.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": { | |
"provenance": [], | |
"authorship_tag": "ABX9TyOL8nZUJHdHad2t+RRaRc7G", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/ttsugriy/635628f829e1a84abdffec272d083ed7/untitled2.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"id": "2wKBUaw6YhHV" | |
}, | |
"outputs": [], | |
"source": [ | |
"import random, typing" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"n = 10 ** 4\n", | |
"data = [random.randint(1, 10 ** 9) for _ in range(n)]" | |
], | |
"metadata": { | |
"id": "BpY7IJKdfTNv" | |
}, | |
"execution_count": 11, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"def sort_local(n: int) -> None:\n", | |
" data = [random.randint(1, 10 ** 9) for i in range(n)]\n", | |
" for i in range(len(data)):\n", | |
" for j in range(i, len(data)):\n", | |
" if data[i] > data[j]:\n", | |
" data[i], data[j] = data[j], data[i]\n", | |
"\n", | |
"%timeit sort_local(n)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "qvvBWyLkf_Ku", | |
"outputId": "3a8af97b-c18b-486e-ba6f-7aef139427b5" | |
}, | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"7.41 s ± 593 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"def sort_global(n: int) -> None:\n", | |
" for i in range(n): data[i] = random.randint(1, 10 ** 9)\n", | |
" for i in range(len(data)):\n", | |
" for j in range(i, len(data)):\n", | |
" if data[i] > data[j]:\n", | |
" data[i], data[j] = data[j], data[i]\n", | |
"\n", | |
"%timeit sort_global(n)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "MKs4Xa9XiwjX", | |
"outputId": "0e344e83-df9c-431a-d3f8-4256d7b00572" | |
}, | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"11.8 s ± 559 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" | |
] | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment