hw brickbench: Benchmark test for NXT and EV3

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: hw brickbench: Benchmark test for NXT and EV3

Post by HaWe »

which leJOS user may provide data about the leJOS progamming environment for NXT and EV§? (the question marks in the second part of the table)?

http://www.mindstormsforum.de/viewtopic ... 095#p64772
Last edited by HaWe on 04 Jan 2015, 14:23, edited 1 time in total.
Stryker295
Posts: 46
Joined: 29 Sep 2014, 09:53
Location: Arizona, USA
Contact:

Re: hw brickbench: Benchmark test for NXT and EV3

Post by Stryker295 »

HaWe wrote:(RobotC firmware and original Lego/NXC firmware are incompatible)—note that Robotc on EV3 just has 15 kbytes RAM for variables just like on the NXT (others have 40+ Mbyte RAM) and additionally no double-precision float (= 64bit) like all others for EV3 (what both is indispensible IMO for a 32bit platform).
Interesting! I have access to neither NXT nor EV3, but I'm hoping to eventually have my NXT shipped back here. I may just have to write all my code in NXC and then attempt to port/rewrite it for RobotC and switch firmwares back and forth for testing... Mainly I do lots of heavy calculations: 2-dimensional balancing/object tracking/obstacle avoidance, realtime inverse kinatics/object tracking/trajectory computing ... etc. Obviously this is math-heavy, so deals with variables, but also needs to be quite snappy...

Ahh. Things are complicated now, but eventually they will be simplified, when I get my hands back on my NXT. Or have a few hundred dollars to throw away on a EV3... Perhaps next Black Friday? :p
—Jag
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: hw brickbench: Benchmark test for NXT and EV3

Post by HaWe »

just not to get this issue lost:

HaWe wrote:which leJOS user may provide data about the leJOS progamming environment for NXT and EV§? (the question marks in the second part of the table)?

http://www.mindstormsforum.de/viewtopic ... 095#p64772
Last edited by HaWe on 04 Jan 2015, 14:23, edited 1 time in total.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: hw brickbench: Benchmark test for NXT and EV3

Post by HaWe »

BTW,
there are also some code issues about the Java version - at least 1 test does not match exactly the reference code (Integer algebra, IIRC).
Maybe a Java expert could fix this, too ?

http://www.mindstormsforum.de/viewtopic ... 501#p64501

For the moment the Java results are not 100% comparable to the others.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: hw brickbench: Benchmark test for NXT and EV3

Post by HaWe »

hi,
is anyone around here who already the new leJOS 0.9 beta?

would you please be so kind and test the following code?
a) just 1 run
b) maybe additionally for the 3rd of 3 runs or for the mean of overall 3 runs

just compile, upload, and copy the program output . that's it!

this is the test code - thanks in advance! 8-)

Code: Select all

import lejos.hardware.Button;
import lejos.hardware.ev3.LocalEV3;
import lejos.hardware.lcd.GraphicsLCD;
import lejos.hardware.lcd.LCD;

// hw brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: leJOS/EV3 0.9.x
// Autor: (C) Helmut Wunder 2013,2014
// Ported to leJOS by Andy Shaw.
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach Genehmigung durch den Autor.
// protected under the friendly Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// http://creativecommons.org/licenses/by-nc-sa/3.0/
// version 1.09.2.ev3 release 2015-02

// PLEASE NOTE: This is not a good example of a Java program. It is a simple port of a C program. 
// No attempt has been made to make use of Java features.

public class MBBenchmark
{
    static long[] runtime = new long[8];
    static int[] a = new int[500], b = new int[500], c = new int[500],
            t = new int[500];

    // --------------------------------------------
    // Mersenne Twister
    // --------------------------------------------

    static int[] y = new int[25];
    static int index = 25 + 1;
    static final int M = 7;
    static final int[] A = { 0, 0x8ebfd028 };

    static int randM()
    {

        if (index >= 25)
        {
            int k;
            if (index > 25)
            {
                int r = 9, s = 3402;
                for (k = 0; k < 25; ++k)
                {
                    r = 509845221 * r + 3;
                    s *= s + 1;
                    y[k] = s + (r >> 10);
                }
            }
            for (k = 0; k < 25 - M; ++k)
                y[k] = y[k + M] ^ (y[k] >> 1) ^ A[y[k] & 1];
            for (; k < 25; ++k)
                y[k] = y[k + (M - 25)] ^ (y[k] >> 1) ^ A[y[k] & 1];
            index = 0;
        }

        int e = y[index++];
        e ^= (e << 7) & 0x2b5b2500;
        e ^= (e << 15) & 0xdb8b0000;
        e ^= (e >> 16);
        return e;
    }

    // --------------------------------------------
    // Matrix Algebra
    // --------------------------------------------

    // matrix * matrix multiplication (matrix product)

    static void MatrixMatrixMult(int N, int M, int K, double A[][],
            double B[][], double C[][])
    {
        int i, j, s; // matrix A: N x M // B: M x K // C: N x K
        for (i = 0; i < N; ++i)
        {
            for (j = 0; j < K; ++j)
            {
                C[i][j] = 0;
                for (s = 0; s < M; ++s)
                {
                    C[i][j] = C[i][j] + A[i][s] * B[s][j];
                }
            }
        }
    }

    // matrix determinant

    static double MatrixDet(int N, double A[][])
    {
        int i, j, i_count, j_count, count = 0;
        double[][] Asub = new double[N - 1][N - 1];
        double det = 0;

        if (N == 1)
            return A[0][0];
        if (N == 2)
            return (A[0][0] * A[1][1] - A[0][1] * A[1][0]);

        for (count = 0; count < N; count++)
        {
            i_count = 0;
            for (i = 1; i < N; i++)
            {
                j_count = 0;
                for (j = 0; j < N; j++)
                {
                    if (j == count)
                        continue;
                    Asub[i_count][j_count] = A[i][j];
                    j_count++;
                }
                i_count++;
            }
            det += Math.pow(-1, count) * A[0][count] * MatrixDet(N - 1, Asub);
        }
        return det;
    }

    // --------------------------------------------
    // shell sort
    // --------------------------------------------

    static void shellsort(int size, int[] A)
    {
        int i, j, increment;
        int temp;
        increment = size / 2;

        while (increment > 0)
        {
            for (i = increment; i < size; i++)
            {
                j = i;
                temp = A[i];
                while ((j >= increment) && (A[j - increment] > temp))
                {
                    A[j] = A[j - increment];
                    j = j - increment;
                }
                A[j] = temp;
            }

            if (increment == 2)
                increment = 1;
            else
                increment = (int) (increment / 2.2);
        }
    }

    // --------------------------------------------
    // benchmark test procedures
    // --------------------------------------------

    static int test_Int_Add()
    {
        int i = 1, j = 11, k = 112, l = 1111, m = 11111, n = -1, o = -11, p = -111, q = -1112, r = -11111;
        int x;
        int s = 0;
        for (x = 0; x < 10000; ++x)
        {
            s += i;
            s += j;
            s += k;
            s += l;
            s += m;
            s += n;
            s += o;
            s += p;
            s += q;
            s += r;
        }
        return s;
    }

    static int test_Int_Mult()
    {
        int x, y;
        int s = 0;

        for (y = 0; y < 2000; ++y)
        {
            s = 1;
            for (x = 1; x <= 13; ++x)
            {
                s *= x;
            }
            for (x = 13; x > 0; --x)
            {
                s /= x;
            }
        }
        return s;
    }

    static float test_float_math()
    {

        float s = (float) Math.PI;
        int y;

        for (y = 0; y < 1000; ++y)
        {
            s *= Math.sqrt(s);
            s = (float) Math.sin(s);
            s = (float) Math.exp(s);
            s *= s;
        }
        return s;
    }

    static int test_rand_MT()
    {
        int s = 0;
        int y;

        for (y = 0; y < 5000; ++y)
        {
            s = randM() % 10001;
        }
        return s;
    }

    static float test_matrix_math()
    {
        int x;

        double[][] A = new double[2][2], B = new double[2][2], C = new double[2][2];
        double[][] O = new double[3][3], T = new double[3][3];
        int s;

        for (x = 0; x < 250; ++x)
        {

            A[0][0] = 1;
            A[0][1] = 3;
            A[1][0] = 2;
            A[1][1] = 4;

            B[0][0] = 10;
            B[0][1] = 30;
            B[1][0] = 20;
            B[1][1] = 40;

            MatrixMatrixMult(2, 2, 2, A, B, C);

            A[0][0] = 1;
            A[0][1] = 3;
            A[1][0] = 2;
            A[1][1] = 4;

            MatrixDet(2, A);

            O[0][0] = 1;
            O[0][1] = 4;
            O[0][2] = 7;
            O[1][0] = 2;
            O[1][1] = 5;
            O[1][2] = 8;
            O[2][0] = 3;
            O[2][1] = 6;
            O[2][2] = 9;

            MatrixDet(3, O);

        }

        s = (int) (O[0][0] * O[1][1] * O[2][2]);
        return s;
    }

    static int test_Sort()
    {
        int y;
        int[] t = new int[500];

        for (y = 0; y < 50; ++y)
        {
            System.arraycopy(a, 0, t, 0, t.length);
            shellsort(500, t);
            System.arraycopy(b, 0, t, 0, t.length);
            shellsort(500, t);
            System.arraycopy(c, 0, t, 0, t.length);
            shellsort(500, t);
        }

        return y;
    }

    static long test_TextOut()
    {

        int y;

        for (y = 0; y < 20; ++y)
        {
            LCD.clear();

            LCD.drawString("" + 0 + " " + 1000 + "  int_Add", 0, 0);
            LCD.drawString("" + 0 + " " + 1010 + "  int_Mult", 0, 1);
            LCD.drawString("" + 0 + " " + 1020 + "  float_op", 0, 2);
            LCD.drawString("" + 0 + " " + 1030 + "  randomize", 0, 3);
            LCD.drawString("" + 0 + " " + 1040 + "  matrix_algb", 0, 4);
            LCD.drawString("" + 0 + " " + 1050 + "  arr_sort", 0, 5);
            LCD.drawString("" + 0 + " " + 1060 + "  display_text", 0, 6);
            LCD.drawString("" + 0 + " " + 1070 + "  testing...", 0, 7);
        }
        return 99;
    }

    static int test_graphics()
    {
        int x = 1, y;
        GraphicsLCD g = LocalEV3.get().getGraphicsLCD();
        for (y = 0; y < 100; ++y)
        {
            g.clear();
            g.drawArc(50, 40, 10, 10, 0, 360);
            g.fillArc(30, 24, 10, 10, 0, 360);
            g.drawLine(10, 10, 60, 60);
            g.drawLine(50, 20, 90, 70);
            g.drawRect(20, 20, 40, 40);
            g.fillRect(65, 25, 20, 30);
            g.drawArc(100, 30, 15, 20, 0, 360);
        }
        return x;
    }


    static void displayValue(int testNo, long testTime, String testName)
    {
        LCD.drawInt(testNo, 2, 0, testNo);
        LCD.drawInt((int) testTime, 6, 3, testNo);
        LCD.drawString(testName, 10, testNo);
    }

    static void displayValues()
    {
        displayValue(0, runtime[0], "int_Add");
        displayValue(1, runtime[1], "int_Mult");
        displayValue(2, runtime[2], "float_op");
        displayValue(3, runtime[3], "randomize");
        displayValue(4, runtime[4], "matrix_algb");
        displayValue(5, runtime[5], "arr_sort");
        displayValue(6, runtime[6], "displ_txt");
        displayValue(7, runtime[7], "graphics");
    }

    static public void main(String[] args)
    {

        long time0;
        int x, y;
        float s;
        int i;

        LCD.clear();
        LCD.drawString("hw brickbench", 0, 1);
        LCD.drawString("(C)H.Wunder 2013", 0, 2);
        LCD.drawString("initializing...", 0, 4);

        // Java on the EV3 uses a JIT compiler, run the test multiple times to
        // allow the results to be stable
        for (int ii = 0; ii < 20; ii++)
        {

            for (y = 0; y < 500; ++y)
            {
                a[y] = randM() % 30000;
                b[y] = randM() % 30000;
                c[y] = randM() % 30000;
            }

            LCD.clear();

            time0 = System.currentTimeMillis();
            s = test_Int_Add();
            runtime[0] = System.currentTimeMillis() - time0;
            displayValue(0, runtime[0], "int_Add ");
            System.out.println("int_Add " + runtime[0]);

            time0 = System.currentTimeMillis();
            s = test_Int_Mult();
            runtime[1] = System.currentTimeMillis() - time0;
            displayValue(1, runtime[1], "int_Mult");
            System.out.println("int_Mult " + runtime[1]);

            time0 = System.currentTimeMillis();
            s = test_float_math();
            runtime[2] = System.currentTimeMillis() - time0;
            displayValue(2, runtime[2], "float_op");
            System.out.println("float_op " + runtime[2]);

            time0 = System.currentTimeMillis();
            s = test_rand_MT();
            runtime[3] = System.currentTimeMillis() - time0;
            displayValue(3, runtime[3], "randomize");
            System.out.println("randomize " + runtime[3]);

            time0 = System.currentTimeMillis();
            s = test_matrix_math();
            runtime[4] = System.currentTimeMillis() - time0;
            displayValue(4, runtime[4], "matrix_algb");
            System.out.println("matrx_algb " + runtime[4]);

            time0 = System.currentTimeMillis();
            s = test_Sort();
            runtime[5] = System.currentTimeMillis() - time0;
            displayValue(5, runtime[5], "arr_sort");
            System.out.println("arr_sort " + runtime[5]);

            time0 = System.currentTimeMillis();
            s = test_TextOut();
            runtime[6] = System.currentTimeMillis() - time0;
            System.out.println("text " + runtime[6]);
            LCD.clear();
            displayValues();

            time0 = System.currentTimeMillis();
            s = test_graphics();
            runtime[7] = System.currentTimeMillis() - time0;
            System.out.println("graphics " + runtime[7]);
            LCD.clear();
            displayValues();
        }
        Button.waitForAnyPress();
        LCD.clear();
        y = 0;
        for (x = 0; x < 8; ++x)
        {
            y += runtime[x];
        }
        LCD.drawString("Total ms: " + y, 0, 0);
        LCD.drawString("Benchmark: " + (50000000 / y), 0, 1);
        System.out.println("total ms: " + y);
        System.out.println("benchmark: " + 50000000 / y);
        Button.waitForAnyPress();
        LCD.clear();
    }

}
Last edited by HaWe on 17 Feb 2015, 11:04, edited 2 times in total.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: hw brickbench: Benchmark test for NXT and EV3

Post by HaWe »

runtime results for java 0.9.0 EV3 now already have been provided:

Output redirected
Executing jrun -cp /home/lejos/programs/MBBenchmark.jar lejos.internal.ev3.EV3Wrapper MBBenchmark in /home/lejos/programs
int_Add 62
int_Mult 61
float_op 195
randomize 20
matrx_algb 159
arr_sort 180
text 277
graphics 689

int_Add 70
int_Mult 91
float_op 267
randomize 25
matrx_algb 47
arr_sort 134
text 174
graphics 364

int_Add 2
int_Mult 15
float_op 159
randomize 5
matrx_algb 42
arr_sort 129
text 174
graphics 364

int_Add 2
int_Mult 10
float_op 88
randomize 4
matrx_algb 47
arr_sort 141
text 194
graphics 333

int_Add 2
int_Mult 9
float_op 48
randomize 5
matrx_algb 49
arr_sort 136
text 200
graphics 539

overview: http://www.mindstormsforum.de/viewtopic ... 772#p64772
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: hw brickbench: Benchmark test for NXT and EV3

Post by HaWe »

Now for leJOS for NXT:
is someone around who would test the following fixed test on an NXT?
thanks in advance!

Code: Select all

import javax.microedition.lcdui.Graphics;

import lejos.nxt.Button;
import lejos.nxt.LCD;


// hw brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: leJOS/NXT 0.9.1beta
// Autor: (C) Helmut Wunder 2013,2014
// Ported to leJOS by Andy Shaw.
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach Genehmigung durch den Autor.
// protected under the friendly Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// http://creativecommons.org/licenses/by-nc-sa/3.0/
// version 1.09.2.nxt

// PLEASE NOTE: This is not a good example of a Java program. It is a simple port of a C program.
// No attempt has been made to make use of Java features.

public class MBBenchmark
{
    static long[] runtime = new long[8];
    static int[] a = new int[500], b = new int[500], c = new int[500],
            t = new int[500];

    // --------------------------------------------
    // Mersenne Twister
    // --------------------------------------------

    static int[] y = new int[25];
    static int index = 25 + 1;
    static final int M = 7;
    static final int[] A = { 0, 0x8ebfd028 };

    static int randM()
    {

        if (index >= 25)
        {
            int k;
            if (index > 25)
            {
                int r = 9, s = 3402;
                for (k = 0; k < 25; ++k)
                {
                    r = 509845221 * r + 3;
                    s *= s + 1;
                    y[k] = s + (r >> 10);
                }
            }
            for (k = 0; k < 25 - M; ++k)
                y[k] = y[k + M] ^ (y[k] >> 1) ^ A[y[k] & 1];
            for (; k < 25; ++k)
                y[k] = y[k + (M - 25)] ^ (y[k] >> 1) ^ A[y[k] & 1];
            index = 0;
        }

        int e = y[index++];
        e ^= (e << 7) & 0x2b5b2500;
        e ^= (e << 15) & 0xdb8b0000;
        e ^= (e >> 16);
        return e;
    }

    // --------------------------------------------
    // Matrix Algebra
    // --------------------------------------------

    // matrix * matrix multiplication (matrix product)

    static void MatrixMatrixMult(int N, int M, int K, double A[][],
            double B[][], double C[][])
    {
        int i, j, s; // matrix A: N x M // B: M x K // C: N x K
        for (i = 0; i < N; ++i)
        {
            for (j = 0; j < K; ++j)
            {
                C[i][j] = 0;
                for (s = 0; s < M; ++s)
                {
                    C[i][j] = C[i][j] + A[i][s] * B[s][j];
                }
            }
        }
    }

    // matrix determinant

    static double MatrixDet(int N, double A[][])
    {
        int i, j, i_count, j_count, count = 0;
        double[][] Asub = new double[N - 1][N - 1];
        double det = 0;

        if (N == 1)
            return A[0][0];
        if (N == 2)
            return (A[0][0] * A[1][1] - A[0][1] * A[1][0]);

        for (count = 0; count < N; count++)
        {
            i_count = 0;
            for (i = 1; i < N; i++)
            {
                j_count = 0;
                for (j = 0; j < N; j++)
                {
                    if (j == count)
                        continue;
                    Asub[i_count][j_count] = A[i][j];
                    j_count++;
                }
                i_count++;
            }
            det += Math.pow(-1, count) * A[0][count] * MatrixDet(N - 1, Asub);
        }
        return det;
    }

    // --------------------------------------------
    // shell sort
    // --------------------------------------------

    static void shellsort(int size, int[] A)
    {
        int i, j, increment;
        int temp;
        increment = size / 2;

        while (increment > 0)
        {
            for (i = increment; i < size; i++)
            {
                j = i;
                temp = A[i];
                while ((j >= increment) && (A[j - increment] > temp))
                {
                    A[j] = A[j - increment];
                    j = j - increment;
                }
                A[j] = temp;
            }

            if (increment == 2)
                increment = 1;
            else
                increment = (int) (increment / 2.2);
        }
    }

    // --------------------------------------------
    // benchmark test procedures
    // --------------------------------------------

    static int test_Int_Add()
    {
        int i = 1, j = 11, k = 112, l = 1111, m = 11111, n = -1, o = -11, p = -111, q = -1112, r = -11111;
        int x;
        int s = 0;
        for (x = 0; x < 10000; ++x)
        {
            s += i;
            s += j;
            s += k;
            s += l;
            s += m;
            s += n;
            s += o;
            s += p;
            s += q;
            s += r;
        }
        return s;
    }

    static int test_Int_Mult()
    {
        int x, y;
        int s = 0;

        for (y = 0; y < 2000; ++y)
        {
            s = 1;
            for (x = 1; x <= 13; ++x)
            {
                s *= x;
            }
            for (x = 13; x > 0; --x)
            {
                s /= x;
            }
        }
        return s;
    }

    static float test_float_math()
    {

        float s = (float) Math.PI;
        int y;

        for (y = 0; y < 1000; ++y)
        {
            s *= Math.sqrt(s);
            s = (float) Math.sin(s);
            s = (float) Math.exp(s);
            s *= s;
        }
        return s;
    }



    static int test_rand_MT()
    {
        int s = 0;
        int y;

        for (y = 0; y < 5000; ++y)
        {
            s = randM() % 10001;
        }
        return s;
    }

    static float test_matrix_math()
    {
        int x;

        double[][] A = new double[2][2], B = new double[2][2], C = new double[2][2];
        double[][] O = new double[3][3], T = new double[3][3];
        int s;

        for (x = 0; x < 250; ++x)
        {

            A[0][0] = 1;
            A[0][1] = 3;
            A[1][0] = 2;
            A[1][1] = 4;

            B[0][0] = 10;
            B[0][1] = 30;
            B[1][0] = 20;
            B[1][1] = 40;

            MatrixMatrixMult(2, 2, 2, A, B, C);

            A[0][0] = 1;
            A[0][1] = 3;
            A[1][0] = 2;
            A[1][1] = 4;

            MatrixDet(2, A);

            O[0][0] = 1;
            O[0][1] = 4;
            O[0][2] = 7;
            O[1][0] = 2;
            O[1][1] = 5;
            O[1][2] = 8;
            O[2][0] = 3;
            O[2][1] = 6;
            O[2][2] = 9;

            MatrixDet(3, O);

        }

        s = (int) (O[0][0] * O[1][1] * O[2][2]);
        return s;
    }

    static int test_Sort()
    {
        int y;
        int[] t = new int[500];

        for (y = 0; y < 50; ++y)
        {
            System.arraycopy(a, 0, t, 0, t.length);
            shellsort(500, t);
            System.arraycopy(b, 0, t, 0, t.length);
            shellsort(500, t);
            System.arraycopy(c, 0, t, 0, t.length);
            shellsort(500, t);
        }

        return y;
    }

    static long test_TextOut()
    {

        int y;

        for (y = 0; y < 20; ++y)
        {
            LCD.clear();

            LCD.drawString("" + 0 + " " + 1000 + "  int_Add", 0, 0);
            LCD.drawString("" + 0 + " " + 1010 + "  int_Mult", 0, 1);
            LCD.drawString("" + 0 + " " + 1020 + "  float_op", 0, 2);
            LCD.drawString("" + 0 + " " + 1030 + "  randomize", 0, 3);
            LCD.drawString("" + 0 + " " + 1040 + "  matrix_algb", 0, 4);
            LCD.drawString("" + 0 + " " + 1050 + "  arr_sort", 0, 5);
            LCD.drawString("" + 0 + " " + 1060 + "  display_text", 0, 6);
            LCD.drawString("" + 0 + " " + 1070 + "  testing...", 0, 7);
        }
        return 99;
    }

    static int test_graphics()
    {
        int x = 1, y;
        Graphics g = new Graphics();;
        for (y = 0; y < 100; ++y)
        {
            g.clear();
            g.drawArc(50, 40, 10, 10, 0, 360);
            g.fillArc(30, 24, 10, 10, 0, 360);
            g.drawLine(10, 10, 60, 60);
            g.drawLine(50, 20, 90, 70);
            g.drawRect(20, 20, 40, 40);
            g.fillRect(65, 25, 20, 30);
            g.drawArc(100, 30, 15, 20, 0, 360);
        }
        return x;
    }


    static void displayValue(int testNo, long testTime, String testName)
    {
        LCD.drawInt(testNo, 2, 0, testNo);
        LCD.drawInt((int) testTime, 6, 3, testNo);
        LCD.drawString(testName, 10, testNo);
    }

    static void displayValues()
    {
        displayValue(0, runtime[0], "int_Add");
        displayValue(1, runtime[1], "int_Mult");
        displayValue(2, runtime[2], "float_op");
        displayValue(3, runtime[3], "randomize");
        displayValue(4, runtime[4], "matrix_algb");
        displayValue(5, runtime[5], "arr_sort");
        displayValue(6, runtime[6], "displ_txt");
        displayValue(7, runtime[7], "graphics");
    }

    static public void main(String[] args)
    {

        long time0;
        int x, y;
        float s;
        int i;

        LCD.clear();
        LCD.drawString("hw brickbench", 0, 1);
        LCD.drawString("(C)H.Wunder 2013", 0, 2);
        LCD.drawString("initializing...", 0, 4);

            for (y = 0; y < 500; ++y)
            {
                a[y] = randM() % 30000;
                b[y] = randM() % 30000;
                c[y] = randM() % 30000;
            }

            LCD.clear();

        time0 = System.currentTimeMillis();
        s = test_Int_Add();
        runtime[0] = System.currentTimeMillis() - time0;
        displayValue(0, runtime[0], "int_Add ");
        System.out.println("int_Add " + runtime[0]);

        time0 = System.currentTimeMillis();
        s = test_Int_Mult();
        runtime[1] = System.currentTimeMillis() - time0;
        displayValue(1, runtime[1], "int_Mult");
        System.out.println("int_Mult " + runtime[1]);

        time0 = System.currentTimeMillis();
        s = test_float_math();
        runtime[2] = System.currentTimeMillis() - time0;
        displayValue(2, runtime[2], "float_op");
        System.out.println("float_op " + runtime[2]);

        time0 = System.currentTimeMillis();
        s = test_rand_MT();
        runtime[3] = System.currentTimeMillis() - time0;
        displayValue(3, runtime[3], "randomize");
        System.out.println("randomize " + runtime[3]);

        time0 = System.currentTimeMillis();
        s = test_matrix_math();
        runtime[4] = System.currentTimeMillis() - time0;
        displayValue(4, runtime[4], "matrix_algb");
        System.out.println("matrx_algb " + runtime[4]);

        time0 = System.currentTimeMillis();
        s = test_Sort();
        runtime[5] = System.currentTimeMillis() - time0;
        displayValue(5, runtime[5], "arr_sort");
        System.out.println("arr_sort " + runtime[5]);

        time0 = System.currentTimeMillis();
        s = test_TextOut();
        runtime[6] = System.currentTimeMillis() - time0;
        System.out.println("text " + runtime[6]);
        LCD.clear();
        displayValues();

        time0 = System.currentTimeMillis();
        s = test_graphics();
        runtime[7] = System.currentTimeMillis() - time0;
        System.out.println("graphics " + runtime[7]);
        LCD.clear();
        displayValues();
        Button.waitForAnyPress();
        LCD.clear();
        y = 0;
        for (x = 0; x < 8; ++x)
        {
            y += runtime[x];
        }
        LCD.drawString("Total ms: " + y, 0, 0);
        LCD.drawString("Benchmark: " + (50000000 / y), 0, 1);
        System.out.println("total ms: " + y);
        System.out.println("benchmark: " + 50000000 / y);
        Button.waitForAnyPress();
        LCD.clear();
    }
}
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests