function bench=benchStiffP1(varargin)
% function benchStiffP1()
%   Benchmark function for StiffAssemblingP1 functions.
%
% See also:
%   StiffAssemblingP1base, StiffAssemblingP1OptV0, StiffAssemblingP1OptV1, StiffAssemblingP1OptV2
%   SquareMesh
%
% OptFEM2DP1 [V1.2b1] -    Copyright (C) 2013  CJS (LAGA)
%
%   This file is part of OptFEM2DP1.
%   OptFEM2DP1 is free software: you can redistribute it and/or modify
%   it under the terms of the GNU General Public License as published by
%   the Free Software Foundation, either version 3 of the License, or
%   (at your option) any later version.
%
%   OptFEM2DP1 is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%   GNU General Public License for more details.
%
%   You should have received a copy of the GNU General Public License
%   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  p = inputParser; 
  
  if isOctave()
    p=p.addParamValue('LN', [20:20:100] , @isnumeric );
    p=p.parse(varargin{:});
  else % Matlab
    p.addParamValue('LN', [20:20:100], @isnumeric );
    p.parse(varargin{:});
  end
  k=1;
  for N=p.Results.LN  
    Th=SquareMesh(N);
    fprintf('---------------------------------------------------------\n')
    fprintf('BENCH (Stiffness Matrix Assembling) %d\n',k)
    fprintf(' Vertices number : %d - Triangles number : %d\n',Th.nq,Th.nme)
    fprintf(' Matrix size   : %d\n',Th.nq)
    Lnq(k)=Th.nq;
    tic();
    M=StiffAssemblingP1base(Th.nq,Th.nme,Th.q,Th.me,Th.areas);
    T(k,1)=toc();
    Ldof(k)=length(M);
    fprintf('    CPU times base (ref) : %3.4f (s)\n',T(k,1))
    tic();
    M=StiffAssemblingP1OptV0(Th.nq,Th.nme,Th.q,Th.me,Th.areas);
    T(k,2)=toc();
    fprintf('    CPU times OptV0      : %3.4f (s) - Speed Up X%3.3f\n',T(k,2),T(k,1)/T(k,2))
    tic();
    M=StiffAssemblingP1OptV1(Th.nq,Th.nme,Th.q,Th.me,Th.areas);
    T(k,3)=toc();
    fprintf('    CPU times OptV1      : %3.4f (s) - Speed Up X%3.3f\n',T(k,3),T(k,1)/T(k,3))
    tic();
    M=StiffAssemblingP1OptV2(Th.nq,Th.nme,Th.q,Th.me,Th.areas);
    T(k,4)=toc();
    fprintf('    CPU times OptV2      : %3.4f (s) - Speed Up X%3.3f\n',T(k,4),T(k,1)/T(k,4))
    k=k+1;
  end
  
  bench.T=T;
  bench.Lnq=Lnq;
  bench.Ldof=Ldof;
  bench.LN=p.Results.LN;
  
