import random as rd import time def liste_aleatoire(N, a, b): L, n = [], 0 while n < N: q = rd.randint(a, b) if not q in L : L.append(q) n = n+1 return L temps_L = [] temps_D = [] N = [] for n in range(100, 5100, 100): L = [] D = {} for i in range(n): L.append(rd.randint(0, 10000)) D[rd.randint(0, 10000)] = 1 tl1 = time.time() for k in range(0, 10000): k in L tl2 = time.time() temps_L.append(tl2-tl1) td1 = time.perf_counter() for k in range(0, 10000): k in D td2 = time.perf_counter() temps_D.append(td2-td1) N.append(n) ## import matplotlib.pyplot as plt plt.figure(figsize = [10/2.54, 10/2.54]) plt.plot(N, temps_L,'rs', label = 'liste' ) plt.plot(N, temps_D, 'ko', label = 'dictionnaire') plt.rc('font',family='Times New Roman') plt.rc('text', usetex=True) plt.rcParams['xtick.labelsize'] = 10 plt.rcParams['ytick.labelsize'] = 10 plt.xlabel(r'$n$', fontsize = 12) plt.ylabel(r'$t\, { \mathrm{(s)}}$', fontsize = 12) plt.legend(fontsize = 12) plt.show()