Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. from timeit import timeit
  2. from random import randint
  3.  
  4. def geraLista(tam):
  5. lista = []
  6. for i in range(tam):
  7. n = randint(1,1*tam)
  8. if n not in lista: lista.append(n)
  9. return lista
  10.  
  11. def bubbleSort(lista):
  12. for i in range(0,len(lista)):
  13. for j in range(i+1,len(lista)):
  14. if lista[i] > lista[j]:
  15. auxi = lista[i]
  16. lista[i] = lista[j]
  17. lista[j] = auxi
  18. ordenada = lista
  19. return ordenada
  20.  
  21. tams = []
  22. tempos = []
  23. for tam in range(3000,24001,3000):
  24. lista = geraLista(tam)
  25. tempo = timeit("bubbleSort({})".format(lista),setup="from __main__ import bubbleSort",number=1)
  26. tams.append(tam)
  27. tempos.append(tempo)
  28.  
  29.  
  30. import matplotlib as plt
  31. plt.use('Agg')
  32. import matplotlib.pyplot as plt
  33. def desenhaGrafico(x,y,xl = "Entradas", yl = "Saídas"):
  34. fig = plt.figure(figsize=(10, 8))
  35. ax = fig.add_subplot(111)
  36. ax.plot(x,y, label = "Melhor Tempo")
  37. ax.legend(bbox_to_anchor=(1, 1),bbox_transform=plt.gcf().transFigure)
  38. plt.ylabel(yl)
  39. plt.xlabel(xl)
  40. fig.savefig('graph.png')
  41.  
  42.  
  43. desenhaGrafico(tams, tempos, "Tamanhos(n)", "Tempo(s)")
Add Comment
Please, Sign In to add comment