function prime_test ( )

%*****************************************************************************80
%
%% prime_test() tests prime().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 March 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../prime' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'prime_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test prime().\n' );
 
  n_lo = 1;
  n_hi = 131072;
  n_factor = 2;

  prime_sweep ( n_lo, n_hi, n_factor );
%
%  Had to reduce n_hi because Octave is TOO SLOW!
%
  n_lo = 10;
  n_hi = 1000000;
  n_factor = 10;

  prime_sweep ( n_lo, n_hi, n_factor );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'prime_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( )

  rmpath ( '../prime' );

  return
end
function prime_sweep ( n_lo, n_hi, n_factor )

%*****************************************************************************80
%
%% prime_sweep() does repeated calls to prime().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    21 May 2012
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N_LO, the first value of N.
%
%    integer N_HI, the last value of N.
%
%    integer N_FACTOR, the factor by which to increase N 
%    after each iteration.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'prime_sweep():\n' );
  fprintf ( 1, '  Call PRIME for an increasing series of N values.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '       N        Pi          Time       Ratio\n' );
  fprintf ( 1, '\n' );

  n = n_lo;
  wtime = 0.0;

  while ( n <= n_hi )

    wtime_old = wtime;

    tic;
    primes = prime ( n );
    wtime = toc;

    if ( wtime_old ~= 0.0 ) 
      fprintf ( 1, '%8d  %8d  %14f  %8f\n', n, primes, wtime, wtime / wtime_old );
    else
      fprintf ( 1, '%8d  %8d  %14f\n', n, primes, wtime );
    end

    n = n * n_factor;

  end

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

