ROBOTC.net forums
http://www.robotc.net/forums/

Re: Benchmark Test for NXT and EV3
http://www.robotc.net/forums/viewtopic.php?f=1&t=7534
Page 1 of 1

Author:  Ford Prefect [ Sun Dec 29, 2013 11:25 am ]
Post subject:  Re: Benchmark Test for NXT and EV3

hey,
don't know where my first post has gone -
now here's an update:

Meanwhile also the RobotC benchmark source code is available (many thanks to Xander!) and so already 4 test platforms have been finished :
1) NXT + NXC, BCC 3.3.8.11, JH's EFW
2) EV3 + gpp C (CSLite 2009), BCC 3.3.8.11, Lego std FW (i.e., Lego VM running parallely)
3) NXT + nxtOSEK / TOPPERS/ATK C/C++
4) NXT + RobotC 3.62

Just Java is still missing (for both NXT and EV3 ! - anyone interested to port this code?)
- and of course graphical "languages" like NXT-G and EV3-G (aka X3) are missing, although I actually doubt that this would be possible to do - or at least will be very, very challenging.

Here's the link to the test:

http://sourceforge.net/apps/phpbb/mindboards/viewtopic.php?f=3&t=2035&p=17769#p17769

Author:  Ford Prefect [ Sat Jan 04, 2014 3:07 pm ]
Post subject:  Re: Benchmark Test for NXT and EV3

hey,
are all the results displayed correctly? a friend reported issues about wrong display output (values 5-7 are not displayed).

So could please someone test this code and report the values?
(Don't give up too early: The overall runtime is about 100 sec, all tests just a few seconds, but sorting (6th test) is supposed to be >80 sec.)

edit:
after displaying the test values 0...7 you may proceed by pressing a button,
then the overall time and benchmark should be shown.

Code:
// hw brickbench
// benchmark test for NXT
// PL: ROBOTC 3.62 for NXT
// Autor: (C) Helmut Wunder 2013
// Ported to ROBOTC by Xander Soldaat
// http://botbench.com
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach Genehmigung durch den Autor.
// version 1.08beta


/////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////BENCHMARK FUNCTIONS////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

int a[500], b[500], c[500];
unsigned long runtime[8];

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

// just for this specific implementation:
// always starting with the same seed at either run => so always identical PRN series !

unsigned long randM(void) {
   const int M = 7;
   const unsigned long A[2] = { 0, 0x8ebfd028 };

   static unsigned long y[25];
   static int index = 25 + 1;

   if (index >= 25) {
      int k;
      if (index > 25) {
         unsigned long 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;
   }

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

// A[Ra x Ca] * B[Rb x Cb] = C[Ra x Cb]
// N = Ra
// M = Ca, Rb
// K = Cb
void MatrixMatrixMult(int N, int M, int K, float *A, float *B, float *C) {
   int i, j, s;
   for (i = 0; i < N; ++i) {
      for (j = 0; j < K; ++j) {
         C[i*K+j] = 0;
         for (s = 0; s < M; ++s) {
            C[i*K+j] = C[i*K+j] + A[i*N+s] * B[s*M+j];
         }
      }
   }
}



//float MatrixDet1x1(float *A) {                 // Determinante 1x1
//   return ( A[0]);
//}


float MatrixDet2x2(float *A) {               // Determinante 2x2
   return ( A[0*2+0]*A[1*2+1]- A[0*2+1]*A[1*2+0] );
}


float MatrixDet3x3(float *A) {               // Determinante 3x3
   return (A[0*3+0]*A[1*3+1]*A[2*3+2]
          +A[0*3+1]*A[1*3+2]*A[2*3+0]
          +A[0*3+2]*A[1*3+0]*A[2*3+1]
          -A[0*3+2]*A[1*3+1]*A[2*3+0]
          -A[0*3+1]*A[1*3+0]*A[2*3+2]
          -A[0*3+0]*A[1*3+2]*A[2*3+1]);
}


//--------------------------------------------
// shell sort
//--------------------------------------------
void shellsort(int size, int *A)
{
   int mid = 0;
   for(int m = size/2 ; m > 0; m /= 2)
   {
     for(int j = m; j < size; j++)
     {
       for(int i = j - m; i >= 0; i -= m)
       {
         if(A[i + m] >= A[i])
           break;
         else
         {
           mid = A[i];
           A[i] = A[i + m];
           A[i + m] = mid;
         }
       }
     }
   }
}





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

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;
   volatile long 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;
}



long test_Int_Mult() {
  int x,y;
  volatile long s;
  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;
}


float test_float_math() {
   float s = PI;
   int y;

   for (y = 0; y < 5000; ++y) {
      s *= sqrt(s);
      s = sin(s);
      s *= cos(10.5 * s);
      s = sqrt(s);
      s = exp(s);
   }
   return s;
}


long test_rand_MT() {
   volatile unsigned long s;
   int y;

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

float test_matrix_math() {
   int x;

   float A[2][2], B[2][2], C[2][2];
   float O[3][3]; //, T[3][3];
   unsigned long 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;

      MatrixDet2x2(&A[0][0]);

      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;

      MatrixDet3x3(&O[0][0]);

   }

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


long test_Sort(){
  unsigned long s;
  int y, i;
  int t[500];

  for(y=0;y<30;++y) {
    for(i=0; i<500;++i) {t[i]=a[i];}
    shellsort(500, t);
    for(i=0; i<500;++i) {t[i]=b[i];}
    shellsort(500, t);
    for(i=0; i<500;++i) {t[i]=c[i];}
    shellsort(500, t);
  }

  return y;
}

long test_TextOut() {
   int y;

   for (y = 0; y < 20; ++y) {
      eraseDisplay();

      nxtDisplayTextLine(0, "0, %5d, int_Add", 1000);
      nxtDisplayTextLine(1, "1, %5d, int_Mult", 1010);
      nxtDisplayTextLine(2, "2, %5d, float_op", 1020);
      nxtDisplayTextLine(3, "3, %5d, rand_array", 1030);
      nxtDisplayTextLine(4, "4, %5d, matrx_algb", 1040);
      nxtDisplayTextLine(5, "5, %5d, arr_sort", 1050);
      nxtDisplayTextLine(6, "6, %5d, displ_txt", 1060);
      nxtDisplayTextLine(7, "7, %5d, testing...", 1070);
   }
   return 99;
}


long test_graphics() {
   int x = 0;
   for (int y = 0; y < 100; ++y) {
      eraseDisplay();

      // ROBOTC does not have a draw circle equivalent
      //Drawer::drawCircle(lcd, 50, 40, 10, DrawOpt::draw());
      nxtDrawEllipse(50, 40, 60, 30);

      //Drawer::drawCircleFilled(lcd, 30, 24, 10, DrawOpt::draw());
      nxtFillEllipse(30, 24, 40, 14);

      //Drawer::drawLine(lcd, 10, 10, 60, 60, DrawOpt::draw());
      nxtDrawLine(10, 10, 60, 60);

      //Drawer::drawLine(lcd, 50, 20, 90, 70, DrawOpt::draw());
      nxtDrawLine(50, 20, 90, 70);

      //Drawer::drawRectangle(lcd, 20, 20, 40, 40, DrawOpt::draw());
      nxtDrawRect(20, 20, 40, 40);

      //Drawer::drawRectangleFilled(lcd, 65, 25, 20, 30, DrawOpt::draw());
      nxtFillRect(65, 25, 20, 30);

      //Drawer::drawEllipse(lcd, 70, 30, 15, 20, DrawOpt::draw());
      nxtDrawEllipse(70, 30, 15, 20);
   }
   return x;
}





void displayValues() {
   eraseDisplay();

   nxtDisplayTextLine(0, "0, %5d, int_Add", runtime[0]);
   nxtDisplayTextLine(1, "1, %5d, int_Mult", runtime[1]);
   nxtDisplayTextLine(2, "2, %5d, float_op", runtime[2]);
   nxtDisplayTextLine(3, "3, %5d, rand_array", runtime[3]);
   nxtDisplayTextLine(4, "4, %5d, matrx_algb", runtime[4]);
   nxtDisplayTextLine(5, "5, %5d, arr_sort", runtime[5]);
   nxtDisplayTextLine(6, "6, %5d, displ_txt", runtime[6]);
   nxtDisplayTextLine(7, "7, %5d, graphics", runtime[7]);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////TASKS ///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////


task main {
   unsigned long time0, x, y;
   float s;

   eraseDisplay();

   nxtDisplayTextLine(0, "HaWe_Bench");
   nxtDisplayTextLine(1, "(C)H.Wunder 2013");
   nxtDisplayTextLine(3, "ROBOTC port:");
   nxtDisplayTextLine(4, "Xander Soldaat");
   nxtDisplayTextLine(5, "initializing...");

   //wait1Msec(3000);

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

   nxtDisplayTextLine(6, "done .. go!");
   wait1Msec(2000);
   eraseDisplay();

   time0 = nSysTime;
   s = test_Int_Add();
   runtime[0] = nSysTime - time0;
   nxtDisplayTextLine(0, "1, %5d, int_Add", runtime[0]);

   time0 = nSysTime;
   s = test_Int_Mult();
   runtime[1] = nSysTime - time0;
   nxtDisplayTextLine(1, "1, %5d, int_Mult", runtime[1]);

   time0 = nSysTime;
   s = test_float_math();
   runtime[2] = nSysTime - time0;
   nxtDisplayTextLine(2, "2, %5d, float_op", runtime[2]);

   time0 = nSysTime;
   s = test_rand_MT();
   runtime[3] = nSysTime - time0;
   nxtDisplayTextLine(3, "3, %5d, rand_array", runtime[3]);

   time0 = nSysTime;
   s = test_matrix_math();
   runtime[4] = nSysTime - time0;
   nxtDisplayTextLine(4, "4, %5d, matrx_algb", runtime[4]);

   time0 = nSysTime;
   s = test_Sort();
   runtime[5] = nSysTime - time0;
   nxtDisplayTextLine(5, "5, %5d, arr_sort", runtime[5]);

   time0 = nSysTime;
   s = test_TextOut();
   runtime[6] = nSysTime - time0;

   time0 = nSysTime;
   s = test_graphics();
   runtime[7] = nSysTime - time0;

   displayValues();
   
   
   while (nNxtButtonPressed == kNoButton) ;
   
   
   eraseDisplay();
   y = 0;
   for (x = 0; x < 8; ++x) {
      y += runtime[x];
   }

   nxtDisplayTextLine(0, "sum ms: %d", y);
   nxtDisplayTextLine(1, "benchmark: %d", 50000000/y);
   while (true) EndTimeSlice();
}




thanks in advance!

Author:  Ford Prefect [ Tue Jan 07, 2014 3:54 am ]
Post subject:  Re: Re: Benchmark Test for NXT and EV3

a little help by testing would be very much appreciated!
Thank you!

Author:  Ford Prefect [ Fri Jan 10, 2014 5:22 am ]
Post subject:  Re: Re: Benchmark Test for NXT and EV3

hmmh, well - the helpfulness here in this forum puts in the shade anything previously seen... :(

Author:  mightor [ Sun Jan 12, 2014 2:01 am ]
Post subject:  Re: Re: Benchmark Test for NXT and EV3

Not everyone cares as much about benchmarking as you do. You got a very similar reaction from the Lejos crowd.

I'm quite busy with other, more pressing, things right now. They're a bit higher on my priority list.

= Xander

Author:  MHTS [ Sun Jan 12, 2014 4:56 am ]
Post subject:  Re: Benchmark Test for NXT and EV3

Yep, we are in the peak of the FTC season. FTC issues got my priority.

Author:  Ford Prefect [ Sun Jan 12, 2014 5:50 am ]
Post subject:  Re: Benchmark Test for NXT and EV3

come on, even if it's not on top on everyone's priority list:
honestly, it's a thing of a few minutes: copy and paste the code into your editor, compile and run and see what happens.
If already that's asked too much then this is really embarrassing.

Author:  tito [ Sat Mar 21, 2015 7:10 pm ]
Post subject:  Re: Benchmark Test for NXT and EV3

just found tis one on the recovered mindboards forum:
https://mindboards.org/viewtopic.php?f= ... =10#p18023

Author:  Sigtrygg [ Sun Mar 22, 2015 4:09 pm ]
Post subject:  Re: Benchmark Test for NXT and EV3

Hello Ford Prefect!

I tried your Benchmark code with RobotC 3.62 for NXT. The code was executed well.

The results:
0 --- 781
1 --- 1151
2 --- 413
3 --- 1839
4 --- 585
5 --- 95896
6 --- 33
7 --- 94
sum ms 100792
benchmark: 496

Don't know if this is fast or slow. I never have made a Robot Project for that I realized that robotC was too slow. I made Projects with Arduino Uno, NXT, Robotis CM-530 and EV3. Each microcontroller worked well and fast enough. For NXT and EV3 I only use RobotC.
What I absolutely don't like is the long starting time for the new EV3, but that's because of Linux-System I was told.

Hope, I could help...

Sigtrygg

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/