T0 = []
T1 = []
T2 = []
X = []

for n in range(0,32001,2000):
  X.append(n)
  T0.append(0.0)
  T1.append(0.0)
  T2.append(0.0)
  magma._start()
  ctr = 3
  for j in range(ctr):
    A = random_matrix(GF(2),n,2*n)

    t0 = cputime()
    _ = A.copy().echelonize(algorithm='pluq')
    t0 = cputime(t0)
    T0[-1] += t0

    t1 = cputime()
    _ = A.copy().echelonize(algorithm='m4ri')
    t1 = cputime(t1)
    T1[-1] += t1

    t2 =magma.eval("""
n:=%s;
A:=RandomMatrix(GF(2),n,2*n);
t:=Cputime();
E:=EchelonForm(A);
Cputime(t);
"""%str(n))
    T2[-1] += float(t2)

  T0[-1] = T0[-1]/float(ctr)
  T1[-1] = T1[-1]/float(ctr)
  T2[-1] = T2[-1]/float(ctr)
  
  print n,T0[-1], T1[-1], T2[-1]

import pylab
pylab.clf() # clear the figure first
pylab.figure(1)

# plot some data and add a legend
pylab.plot(X,T0,label="PLUQ") 
pylab.plot(X,T1,label="M4RI") 
pylab.plot(X,T2,label="Magma") 

pylab.legend() # print the legend

pylab.title("Reduced Row Echelon Form")
pylab.ylabel("execution time $t$") # label the axes
pylab.xlabel("matrix dimension $n$ x $2n$")

pylab.savefig('pluq-m4ri-magma-scaled.png',dpi=int(100)) # fire!
