#!/bin/python3

from random import randint
from math   import log
import matplotlib.pyplot as plt
import argument as arg

def trier ( n ) :
	lst  = [ randint(0, n)  for i in range(0, n ) ]
	deb = time.process_time()

	lst.sort()

	fin = time.process_time()

	return ( fin - deb )


arg.cmdline()

from random import randint
import time
print( 'r=', arg.repetition, 'i=',arg.iteration )


x = []
y = []
z = []
f = []
p = []

A=0.51e-8

for n in  range(2 , arg.iteration  ) :
	cpt = 0
	for  r in range( arg.repetition  ) :
		tps =  trier( n )
		cpt += tps
		if r == 0 :
			pire = favo = tps
		if tps > pire:
			pire = tps
		if tps < favo :
			favo = tps
	x.append( n )
	z.append( A * n*log(n)  )
	y.append( cpt / arg.repetition )
	f.append(  favo   )
	p.append(  pire   )

plt.title("Temps de calcul du tri de liste")
plt.ylabel('secondes')
plt.xlabel('n')
plt.plot(x, z,  label='A * n * log(n),   A=' + str(A)  )
plt.plot(x, p,  label='défavorable')
plt.plot(x, y,  label='moyenne')
plt.plot(x, f,  label='favorable' )
plt.legend()
plt.show()
plt.close()


