Created
August 2, 2016 22:15
-
-
Save dyjjones/6ecbdea47e1ee16618a8768afb73b8aa to your computer and use it in GitHub Desktop.
sleep sort
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
from concurrent.futures import ThreadPoolExecutor | |
from time import sleep | |
from collections import Counter | |
from random import shuffle | |
from pprint import pprint | |
x = ThreadPoolExecutor(1000) | |
lst = list(range(10)) | |
def sleepsort(l): | |
sorted_l = [] | |
def handle_n(n): | |
sleep(n*.1) | |
sorted_l.append(n) | |
for num in x.map(handle_n, l): | |
pass | |
return sorted_l | |
results = [] | |
for _ in range(100): | |
shuffle(lst) | |
results.append(tuple(sleepsort(lst))) | |
pprint(dict(Counter(results))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment