View unanswered posts | View active topics It is currently Fri Oct 24, 2014 8:45 pm






Reply to topic  [ 7 posts ] 
Re: Benchmark Test for NXT and EV3 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 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

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sun Dec 29, 2013 11:25 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 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!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Jan 04, 2014 3:07 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Re: Benchmark Test for NXT and EV3
a little help by testing would be very much appreciated!
Thank you!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Tue Jan 07, 2014 3:54 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Re: Benchmark Test for NXT and EV3
hmmh, well - the helpfulness here in this forum puts in the shade anything previously seen... :(

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Jan 10, 2014 5:22 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Jan 12, 2014 2:01 am
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Benchmark Test for NXT and EV3
Yep, we are in the peak of the FTC season. FTC issues got my priority.


Sun Jan 12, 2014 4:56 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 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.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sun Jan 12, 2014 5:50 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.