Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Created May 21, 2013 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fmasanori/5620281 to your computer and use it in GitHub Desktop.
Save fmasanori/5620281 to your computer and use it in GitHub Desktop.
Sort vs Heapq
import time, random
N = 1000000
NL = 1 #100000 10 1
origem = [random.randrange(N) for x in range(N)]
lista = list(origem)
t = time.time()
lista.sort(reverse=True)
print (time.time() - t)
import heapq
lista = list(origem)
t = time.time()
maiores = heapq.nlargest(NL, lista)
print (time.time() - t)
lista = list(origem)
t = time.time()
m = max(lista)
print (time.time() - t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment