/*--------------------------------------------------------------------------*/
/* Ox Benchmark program version 1.1                                         */
/* derived from Stefan Steinhaus's GAUSS benchmark program                  */
/* EMAIL  : stst@informatik.uni-frankfurt.de                                */ 
/* This program is public domain. Feel free to copy it freely.              */

// 27-10-97: version from http://www.uni-frankfurt.de/~stst/ncrunch.html
//           adjusted for Ox 1.20. Also prints total time.
//			 run with -DOLDOX to use under Ox 1.11 or 1.10

#include <oxstd.h>

main()
{
    decl cRep = 3;                                     /* number of repeats */
    decl i, time, a, b, c, secs, tottime;

    print("number of repeats: ", cRep, " (timings in seconds)\n");
	format("%8.3f");

	tottime = timer();

	for (i = secs = 0; i < cRep; ++i)
	{
	    b=fabs(rann(400,400)/10);
    	time = timer();
        a = (b+1) .^ 1000;
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("400x400 random matrix .^ 1000:                       ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
	    a = rann(300,300);
    	time = timer();
        eigen(a, &b);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Eigenvalues of a 300x300 random matrix:              ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
	    a = ranu(500,500);
    	time = timer();
        b = invert(a);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Inverse of a 500x500 random matrix:                  ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
	    a = rann(1,500000);
    	time = timer();
        b = sortr(a);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Sorting of 500,000 random values:                    ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
	    a = range(1,800);
    	time = timer();
        b = toeplitz(a,800);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Creation of an 800x800 Toeplitz matrix:              ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
	    a = rann(500,500); a = a'a;
    	time = timer();
        b = choleski(a);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Choleski decomposition of a 500x500 random matrix:   ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
	    a = rann(500,500);
    	time = timer();
        b = a'a;
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Creation of 500x500 cross-product matrix:            ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
	    a = rann(1, 100000);
    	time = timer();
        b = fft(a);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("FFT over 100,000 random values:                      ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
		a = rann(500, 500).^2;
    	time = timer();
        b = erf(a);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Gaussian error function over a 500x500 random matrix:", secs, "\n");

	// n! = Gamma(n + 1) use gammafact
	for (i = secs = 0; i < cRep; ++i)
	{
   		b=rann(600,600).^2;
    	time = timer();
	    a = gammafact(b);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Gamma function on a 600x600 random matrix:           ", secs, "\n");

	for (i = secs = 0; i < cRep; ++i)
	{
	    a = rann(500,500); b = range(1,500);  c = 0;
    	time = timer();
        olsr(b, a, &c);
		secs += (timer() - time) / 100;
	}
    secs /= cRep;  delete a;  delete b;
    print("Linear regression over a 500x500 random matrix:      ", secs, "\n");

	print("total time:                                       ", timespan(tottime), "\n");
}
/*--------------------------------------------------------------------------*/
