HaWe brickbench Benchmark Test f. NXT, EV3 & andere

Allgemeines und oft gestellte Fragen (z.B. Baukästen, Anleitungen, Projekte...)

Moderator: Moderatoren

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

HaWe brickbench Benchmark Test f. NXT, EV3 & andere

Beitragvon HaWe » 13. Dez 2013 09:51

Projekt: Benchmark Test

NXT (NXC) vs. EV3 (BCC-C)
Code und ab sofort auch alle Ergebnisse ab sofort hier::


Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 29. Dez 2013 19:10

Update: Code für ANSI C, BricxCC/GCC
neue Benchmark-Version!
War nötig wegen Bug im sort-Benchmark:
hier wurde in C immer nur 1x der random array sortiert, danach nur noch der bereits vorsortierte.

Jetzt wurde der C-Code dem NXC-Code angeglichen, der den Original-Array unverändert lässt und nur einen temp-Array sortiert zurückgibt:

Code: Alles auswählen


long test_Sort(){  // für hw brickbench Version 1.07!
  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;
}


edit: Kompletter Source code ein Stückchen weiter unten im Thread!
http://www.mindstormsforum.de/viewtopic.php?p=64772#p64772
Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 15. Apr 2014 08:50

jetzt liegen auch erste Benchmark-Ergebnisse vor für
NXT - leJOS
EV3 - leJOS
EV3 - RobotC
z.Zt teilw. noch unvollständig und ungeprüft, da ohne veröffentlichten Code (soll aber laut Xander (RobotC) und Andy Shaw (leJOS) bald folgen!
- hoffentlich auch bald der nxtOSEK 1.08 Test ;-) )

http://www.mindstormsforum.de/viewtopic.php?p=64772#p64772


Ein ganz herzliches Dankeschön nochmal an alle, die mitgemacht und zu der Übersicht beigetragen haben (namentlich Martin, Xander und Andy) - und hoffentlich auch hier und da weiter am Code feilen!
Auch wenn's sicher keine riesengroße Sache ist - es ist aber meines Wissens weltweit das allererste Mal, dass man verschiedene Mindstorms-Programmierplattformen verlässlich per Software-Tests fundiert überprüfen und vergleichen kann!
8-)
Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E

Martin0x5E
Schreibt super viel
Schreibt super viel
Beiträge: 496
Registriert: 17. Dez 2011 11:39
Wohnort: Österreich

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon Martin0x5E » 15. Apr 2014 13:32

Musste dieses mal den Test von nxtOSEK Bios ausführen (RAM+ROM). Dürfte also im ganzen etwas langsamer laufen.
Beim ausführen direkt auf dem RAM gibt es einen Speicher Fehler. Denke mal das der RAM für die Größe des zur Laufzeit angeforderten Speichers einfach nicht ausreicht. Wäre vielleicht eine Idee für die nächste Version: Arrays wieder kleiner.

Ergebnis:

Code: Alles auswählen

0: 29
1: 182
2: 320
4: 73
5: 68
5: 491
6: 17
7: 182
Ges: 1362
Bench: 36711



Code:

Code: Alles auswählen

// hw brickbench
// benchmark test for NXT
// PL: nxtOSEK TOPPERS/ATK C/C++
// Autor: (C) Helmut Wunder 2013
// Ported to nxtOSEK by Martin Aumair
// http://roboticsaumair.jimdo.com/
// 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.08

extern "C" {
#include "../../../toppers_osek/include/kernel.h"
#include "kernel_id.h"
#include "../../../ecrobot/c/ecrobot_interface.h"
#include "../../../lejos_nxj/src/nxtvm/platform/nxt/mytypes.h"
}

#include "../../../NXtpandedLib/src/LcdDrawer.hpp"

#include "../../../../GNUARM/arm-elf/sys-include/math.h"
//#include "../../../../GNUARM/arm-elf/sys-include/stdio.h"

DeclareTask(TaskMain);

/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////OSEK HOOKS/IRS///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

extern "C" {

// nxtOSEK hook to be invoked from an ISR in category 2
void user_1ms_isr_type2(void) { }

// hooks
void ecrobot_device_initialize(void);
void ecrobot_device_terminate(void);

bool btnhit() {
   return (ecrobot_is_RUN_button_pressed() || ecrobot_is_ENTER_button_pressed());
}

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

using namespace nxpl; // NXtpandedLib

int a[500], b[500], c[500];
NLcd lcd;

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

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


void MatrixMatrixMult(int N, int M, int K, float A[][2], float B[][2], float C[][2]) {
   int i, j, s;
   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];
         }
      }
   }
}



// no VLA!
float MatrixDet(int N, float A[]) {
   int i, j, i_count, j_count, count = 0;
   float Asub[N - 1][N - 1], det = 0;

   if (N == 1)
      return *A;
   if (N == 2)
      return ((*A) * (*(A+1+1*N)) - (*(A+1*N)) * (*(A+1)));

   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*N);
            j_count++;
         }
         i_count++;
      }
      det += pow(-1, count) * A[0+count*N] * MatrixDet(N - 1, &Asub[0][0]);
   }
   return det;
}


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

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 = (unsigned int) (increment / 2.2);
  }
}


//--------------------------------------------
// 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 = M_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;

      MatrixDet(2, &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;

      MatrixDet(3, &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;
}


// helper functions for output
// normally with cout our sprintf but I think in a benchmark we take the fastest method
void NumOut(int x, int y, int num, U32 places) {
   display_goto_xy(x, y);
   display_int(num, places);
}

void TextOut(int x, int y, const char *str) {
   display_goto_xy(x, y);
   display_string(str);
}

long test_TextOut() {
   int y;

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

      // x,y value is line not pixel! nxtOSEK use fast dma update in chars,lines!
      NumOut(0,0, 0, 1); NumOut(2,0, 1000, 4); TextOut(8,0, "int_Add");
      NumOut(0,1, 1, 1); NumOut(2,1, 1010, 4); TextOut(8,1, "int_Mult");
      NumOut(0,2, 2, 1); NumOut(2,2, 1020, 4); TextOut(8,2, "float_op");
      NumOut(0,3, 3, 1); NumOut(2,3, 1030, 4); TextOut(8,3, "rand_array");
      NumOut(0,4, 4, 1); NumOut(2,4, 1040, 4); TextOut(8,4, "matrx_algb");
      NumOut(0,5, 5, 1); NumOut(2,5, 1050, 4); TextOut(8,5, "arr_sort");
      NumOut(0,6, 6, 1); NumOut(2,6, 1060, 4); TextOut(8,6, "displ_txt");
      NumOut(0,7, 7, 1); NumOut(2,7, 1070, 4); TextOut(8,7, "testing...");
      display_update();  // not really good because we can update hardware only every 16 ms
   }
   return 99;
}


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

      // no official functions, its my actual project: NXtpandedLib

      drawCircle(lcd, NPoint(50, 40), 10);
      drawCircleFilled(lcd, NPoint(30, 24), 10);
      drawLine(lcd, NPoint(10, 10), NPoint(60, 60));
      drawLine(lcd, NPoint(50, 20), NPoint(90, 70));
      drawRectangle(lcd, NPixelBox(NPoint(20, 20), 40, 40));
      drawRectangleFilled(lcd, NPixelBox(NPoint(65, 25), 20, 30));
      drawEllipse(lcd, NPoint(70, 30), 15, 20);

      display_update(); // not really good because we can update hardware only every 16 ms
   }
   return x;
}



U32 runtime[8];

void displayValues() {
   display_clear(0);

   NumOut(0,0, 0, 1); NumOut(2,0, (int)runtime[0], 5); TextOut(8,0, "int_Add");
   NumOut(0,1, 1, 1); NumOut(2,1, (int)runtime[1], 5); TextOut(8,1, "int_Mult");
   NumOut(0,2, 2, 1); NumOut(2,2, (int)runtime[2], 5); TextOut(8,2, "float_op");
   NumOut(0,3, 3, 1); NumOut(2,3, (int)runtime[3], 5); TextOut(8,3, "rand_array");
   NumOut(0,4, 4, 1); NumOut(2,4, (int)runtime[4], 5); TextOut(8,4, "matrx_algb");
   NumOut(0,5, 5, 1); NumOut(2,5, (int)runtime[5], 5); TextOut(8,5, "arr_sort");
   NumOut(0,6, 6, 1); NumOut(2,6, (int)runtime[6], 5); TextOut(8,6, "displ_txt");
   NumOut(0,7, 7, 1); NumOut(2,7, (int)runtime[7], 5); TextOut(8,7, "grafics");
}

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


TASK(TaskMain) {
   //test_graphics();
   //display_update();


   unsigned long time0, x, y;
   float s;

   display_clear(1);

   TextOut(0, 0, "hw brickbench");
   TextOut(0, 1, "(C)H.Wunder 2013");
   TextOut(0, 3, "nxtOSEK port:");
   TextOut(0, 4, "Martin Aumair");
   TextOut(0, 5, "initializing...");
   display_update();
   systick_wait_ms(3000);

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

   TextOut(0, 6, "done .. go!");
   display_update();
   systick_wait_ms(2000);
   display_clear(1);

   time0 = systick_get_ms();
   s = test_Int_Add();
   runtime[0] = systick_get_ms() - time0;
   NumOut(0,0, 0, 1); NumOut(2,0, (int)runtime[0], 5); TextOut(8,0, "int_Add");
   display_update();

   time0 = systick_get_ms();
   s = test_Int_Mult();
   runtime[1] = systick_get_ms() - time0;
   NumOut(0,1, 1, 1); NumOut(2,1, (int)runtime[1], 5); TextOut(8,1, "int_Mult");
   display_update();

   time0 = systick_get_ms();
   s = test_float_math();
   runtime[2] = systick_get_ms() - time0;
   NumOut(0,2, 2, 1); NumOut(2,2, (int)runtime[2], 5); TextOut(8,2, "float_op");
   display_update();

   time0 = systick_get_ms();
   s = test_rand_MT();
   runtime[3] = systick_get_ms() - time0;
   NumOut(0,3, 3, 1); NumOut(2,3, (int)runtime[3], 5); TextOut(8,3, "rand_array");
   display_update();

   systick_wait_ms(1500);

   time0 = systick_get_ms();
   s = test_matrix_math();
   runtime[4] = systick_get_ms() - time0;
   NumOut(0,4, 4, 1); NumOut(2,4, (int)runtime[4], 5); TextOut(8,4, "matrx_algb");
   display_update();

   systick_wait_ms(1500);

   time0 = systick_get_ms();
   s = test_Sort();
   runtime[5] = systick_get_ms() - time0;
   NumOut(0,5, 5, 1); NumOut(2,5, (int)runtime[5], 5); TextOut(8,5, "arr_sort");
   display_update();

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


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

   displayValues();

   while (! btnhit() );  //  <<<<< wait for btnpress

   display_clear(1);
   y = 0;
   for (x = 0; x < 8; ++x) {
      y += runtime[x];
   }

   TextOut(0,0, "sum ms:");    NumOut(8,0, y, 7);
   TextOut(0,1, "benchmark:"); NumOut(8,1, 50000000/y, 7);

   systick_wait_ms(1000);
   while (! btnhit() );  //  <<<<< wait for btnpress

   TerminateTask();
}

}
Projekte und Informationen auf meiner Website: http://roboticsaumair.jimdo.com/

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 15. Apr 2014 13:46

ein ganz dickes Dankeschön, Martin! :prima:
:D

ps,
für eine nächste Version würde ich die Tests folgendermaßen abändern/gewichten:

Code: Alles auswählen

integer add/subtr              x4
integer multiply/division      x2
Mersenne bit-shift             x3

Matrix algebra:                x3
array sort: sizes [10]x5, [100]x2, [500]x1

Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 18. Apr 2014 16:42

ANSI C Referenz-Code als Bezug und Basis für Tests auf anderen Plattformen:
s. direkt hier anschließend!


C/C++ Source-Code für Raspberry Pi, ebenfalls als gleichwertige Referenz verwertbar:
viewtopic.php?f=71&t=8095&start=15#p67795


weitere überprüfte Sourcecodes für andere Plattformen hier nachfolgend!

aktuelle Benchmark-Tabelle siehe hier:
http://www.mindstormsforum.de/viewtopic.php?p=64772#p64772

EV3
gpp C/C++ & Code Sourcery Lite toolchains
mit BricxCC und der brickOS C-API von John Hansen

########################################################################################################

Code: Alles auswählen

// HaWe Brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: gpp CSLite C/C++, C-API and BCC by John Hansen
// Autor: (C) Helmut Wunder 2013,2014
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach schriftlicher 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

#include <stdio.h>
#include <math.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

#include "lms2012.h"
#include "ev3_button.h"
#include "ev3_lcd.h"
#include "ev3_constants.h"
#include "ev3_command.h"
#include "ev3_timer.h"
#include "ev3_lcd.h"
#include "ev3_sound.h"
#include "ev3_output.h"


unsigned long runtime[8];

int a[500], b[500], c[500], t[500];


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

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

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

// matrix * matrix multiplication (matrix product)

void MatrixMatrixMult(int N, int M, int K, double A[][M], double B[][K], double C[][K]){
  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

double MatrixDet(int N, double A[N][N])
{
    int i,j,i_count,j_count, count=0;
    double Asub[N-1][N-1], 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 += pow(-1, count) * A[0][count] * MatrixDet(N-1,Asub);
    }
    return det;
}


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

void shellsort(int size, int* A)
{
  volatile int i, j, increment;
  volatile 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 = (unsigned int) (increment / 2.2);
  }
}

//--------------------------------------------
// gnu quick sort
// (0ptional)
//--------------------------------------------

int compare_int (const int *a, const int *b)
{
  volatile int  temp = *a - *b;

  if (temp > 0)          return  1;
  else if (temp < 0)     return -1;
  else                   return  0;
}

// gnu qsort:
// void qsort (void *a , size_a count, size_a size, compare_function)
// gnu qsort call for a[500] array of int:
// qsort (a , 500, sizeof(a), compare_int)



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


int test_Int_Add() {
   volatile int i=1, j=11, k=112, l=1111, m=11111, n=-1, o=-11, p=-111, q=-1112, r=-11111;
   volatile 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;
}


#define PI  M_PI


double test_float_math() {

  volatile double s=PI;
  int y;

  for(y=0;y<1000;++y) {
     s*=sqrt(s);
     s=sin(s);
     s=exp(s);
     s*=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;

  volatile double A[2][2], B[2][2], C[2][2];
  volatile double O[3][3], T[3][3];
  volatile 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;

    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=(O[0][0]*O[1][1]*O[2][2]);
  return s;
}



// for array copy using void *memcpy(void *dest, const void *src, size_t n);

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

  for(y=0;y<30;++y) {
    memcpy(t, a, sizeof(a));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(b));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(c));
    shellsort(500, t);
  }

  return y;
}


//--------------------------------------------
// display tests
//--------------------------------------------


long test_TextOut(){

  int  y;
  char buf[120];

  for(y=0;y<20;++y) {
    LcdClearDisplay();
    sprintf (buf, "%3d %4d  int_Add",    0, 1000); LcdText(1, 0,10, buf);
    sprintf (buf, "%3d %4d  int_Mult",   1, 1010); LcdText(1, 0,20, buf);
    sprintf (buf, "%3d %4d  float_op",   2, 1020); LcdText(1, 0,30, buf);
    sprintf (buf, "%3d %4d  randomize",  3, 1030); LcdText(1, 0,40, buf);
    sprintf (buf, "%3d %4d  matrx_algb", 4, 1040); LcdText(1, 0,50, buf);
    sprintf (buf, "%3d %4d  arr_sort",   5, 1050); LcdText(1, 0,60, buf);
    sprintf (buf, "%3d %4d  displ_txt",  6, 1060); LcdText(1, 0,70, buf);
    sprintf (buf, "%3d %4d  testing...", 7, 1070); LcdText(1, 0,80, buf);

  }
  return 99;
}


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

    LcdClearDisplay();

    CircleOut(50, 40, 10);
    CircleOutEx(30, 24, 10, DRAW_OPT_FILL_SHAPE);
    LineOut(10, 10, 60, 60);
    LineOut(50, 20, 90, 70);
    RectOut(20, 20, 40, 40);
    RectOutEx(65, 25, 20, 30, DRAW_OPT_FILL_SHAPE);
    EllipseOut(70, 30, 15, 20);

  }
  return y;
}


inline void displayValues() {

  char buf[120];

    sprintf (buf, "%3d %7d  int_Add",    0, runtime[0]); LcdText(1, 0,10, buf);
    sprintf (buf, "%3d %7d  int_Mult",   1, runtime[1]); LcdText(1, 0,20, buf);
    sprintf (buf, "%3d %7d  float_op",   2, runtime[2]); LcdText(1, 0,30, buf);
    sprintf (buf, "%3d %7d  randomize",  3, runtime[3]); LcdText(1, 0,40, buf);
    sprintf (buf, "%3d %7d  matrx_algb", 4, runtime[4]); LcdText(1, 0,50, buf);
    sprintf (buf, "%3d %7d  arr_sort",   5, runtime[5]); LcdText(1, 0,60, buf);
    sprintf (buf, "%3d %7d  displ_txt",  6, runtime[6]); LcdText(1, 0,70, buf);
    sprintf (buf, "%3d %7d  graphics",   7, runtime[7]); LcdText(1, 0,80, buf);
}


void Handler(int sig)     //  fix ?
{
  //printf("handler %d\n", sig);   
}


//--------------------------------------------
// main()
//--------------------------------------------
int main(){

  unsigned long time0, x, y;
  float s;
  char  buf[120];
  int   i;

  SetTimerCallback(ti1sec, &Handler);

  ClearTimer(0);
  ClearTimerMS(0);

  ButtonLedInit();
  LcdInit();
  LcdClean();


  LcdText(1, 0,10, "hw brickbench");
  LcdText(1, 0,20, "(C)H.Wunder 2013");
  LcdText(1, 0,50, "initializing...");

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


  LcdClearDisplay();

  time0= TimerMS(0);;
  s=test_Int_Add();
  runtime[0]=TimerMS(0)-time0;
  sprintf (buf, "%3d %7d  int_Add",    0, runtime[0]); LcdText(1, 0,10, buf);

  time0=TimerMS(0);
  s=test_Int_Mult();
  runtime[1]=TimerMS(0)-time0;
  sprintf (buf, "%3d %7d  int_Mult",   0, runtime[1]); LcdText(1, 0,20, buf);

  time0=TimerMS(0);
  s=test_float_math();
  runtime[2]=TimerMS(0)-time0;
  sprintf (buf, "%3d %7d  float_op",   0, runtime[2]); LcdText(1, 0,30, buf);

  time0=TimerMS(0);
  s=test_rand_MT();
  runtime[3]=TimerMS(0)-time0;
  sprintf (buf, "%3d %7d  randomize",  0, runtime[3]); LcdText(1, 0,40, buf);

  time0=TimerMS(0);
  s=test_matrix_math();
  runtime[4]=TimerMS(0)-time0;
  sprintf (buf, "%3d %7d  matrx_algb", 0, runtime[4]); LcdText(1, 0,50, buf);


  time0=TimerMS(0);
  s=test_Sort();
  runtime[5]=TimerMS(0)-time0;
  sprintf (buf, "%3d %7d  arr_sort",   0, runtime[5]); LcdText(1, 0,60, buf);

  time0=TimerMS(0);
  s=test_TextOut();
  runtime[6]=TimerMS(0)-time0;
  LcdClearDisplay();
  displayValues();

  time0=TimerMS(0);
  s=test_graphics();
  runtime[7]=TimerMS(0)-time0;
  LcdClearDisplay();
  displayValues();


  LcdText(1, 0,100, "cont: press btn < LEFT...");

  while(ButtonWaitForAnyPress(100) != BUTTON_ID_LEFT);

  LcdClearDisplay();
  y=0;
  for(x=0;x<8;++x) {y+= runtime[x];}

  sprintf (buf, "gesamt ms: %d ", y);           LcdText(1, 0,10, buf);
  sprintf (buf, "benchmark: %d ", 50000000/y ); LcdText(1, 0,20, buf);

  LcdText(1, 0,40, "quit: press btn < LEFT...");   // to be fixed  ! <<<<<<<<< no reaction, just for left + ESC !

  while(ButtonWaitForAnyPress(100) != BUTTON_ID_LEFT);

  LcdExit();
  ButtonLedExit();
  return 1;

}

########################################################################################################

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 19. Apr 2014 09:21

als Zwischenstand, zum Speichern:


This benchmark test is including several test functions for different individual computation patterns:
- simple basic integer arithmetics (addition/substraction, multiplication/division),
- real and transcendental float arithmetic functions (sqrt,sin,cos, exp), preferably 64bit double (=> bonus points)
- advanced matrix algebra for more-dim array manipulation (matrix product + determinant, built-in or imported) (genuine multi-dim arrays => bonus points)
- pseudo random number generator (Mersenne Twister): low-level bit- and-byte-operations like AND, XOR, SHIFT-left/right
- quick high-level sort algorithm for arrays[500] (preferably Shellsort, built-in or imported),
- a text-output and a 2D-graphics test for graph + shape + fill computation and lcd output stressing.

the latest brickbench test enhancement also takes environmental aspects into account, i.e.
- available memory, networking/chaining abilities, variable types (e.g. for double precision fp and matrices/more-dim arrays),
- multithreading support
- and, last but not least, the wholeness of API functions for hardware (screen, and attached sensors and motors)

Platforms and source codes:

Code reference: http://www.mindstormsforum.de/viewtopic.php?f=71&t=8095&p=64494#p64494
Meanwhile 7 test platforms have been almost finished:

1) EV3 + gpp C (CSLite 2009), BCC 3.3.8.11, J.H.'s C-API, Lego FW (VM running parallely) << code reference !
2) NXT + NXC, BCC 3.3.8.11, JH's EFW
3) NXT + nxtOSEK / TOPPERS/ATK C/C++
4) NXT + RobotC 3.62
5) NXT + leJOS 0.9x beta
6) EV3 + leJOS 0.8x alpha
7) EV3 + RobotC 4.x pre-alpha
update:
8) + 9): for EV3 + Mono/C# and Arduino Due, work is in progress!

max execution speed is sought of course, but no buffers are allowed, display output refresh has to be adjusted for max speed (e.g., for nxtOSEK), and measures must be taken to avoid that the compiler optimizes out calculations ((e.g., for "real" C by defining variables as "volatile" ).
########################################################################################################

EV3 + BCC/C: gpp C/C++, CSLite Toolchains 2009

Code: Alles auswählen

// hw brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: gpp CSLite C/C++, C-API and BCC by John Hansen
// Autor: (C) Helmut Wunder 2013,2014
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach schriftlicher 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.1

#include <stdio.h>
#include <math.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

#include "lms2012.h"
#include "ev3_button.h"
#include "ev3_lcd.h"
#include "ev3_constants.h"
#include "ev3_command.h"
#include "ev3_timer.h"
#include "ev3_lcd.h"
#include "ev3_sound.h"
#include "ev3_output.h"


unsigned long runtime[8];

int a[500], b[500], c[500], t[500];


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

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

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

// matrix * matrix multiplication (matrix product)

void MatrixMatrixMult(int N, int M, int K, double A[][M], double B[][K], double C[][K]){
  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

double MatrixDet(int N, double A[N][N])
{
    int i,j,i_count,j_count, count=0;
    double Asub[N-1][N-1], 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 += pow(-1, count) * A[0][count] * MatrixDet(N-1,Asub);
    }
    return det;
}


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

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 = (unsigned int) (increment / 2.2);
  }
}

//--------------------------------------------
// gnu quick sort
// (0ptional)
//--------------------------------------------

int compare_int (const int *a, const int *b)
{
  int  temp = *a - *b;

  if (temp > 0)          return  1;
  else if (temp < 0)     return -1;
  else                   return  0;
}

// gnu qsort:
// void qsort (void *a , size_a count, size_a size, compare_function)
// gnu qsort call for a[500] array of int:
// qsort (a , 500, sizeof(a), compare_int)



//--------------------------------------------
// 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;
}


#define PI  M_PI


double test_float_math() {

  volatile double s=PI;
  int y;

  for(y=0;y<1000;++y) {
     s*=sqrt(s);
     s=sin(s);
     s=exp(s);
     s*=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;

  double A[2][2], B[2][2], C[2][2];
  double 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;

    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=(O[0][0]*O[1][1]*O[2][2]);
  return s;
}



// for array copy using void *memcpy(void *dest, const void *src, size_t n);

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

  for(y=0;y<30;++y) {
    memcpy(t, a, sizeof(a));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(b));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(c));
    shellsort(500, t);
  }

  return y;
}



long test_TextOut(){

  int  y;
  char buf[120];

  for(y=0;y<20;++y) {
    LcdClearDisplay();
    sprintf (buf, "%3d %4d  int_Add",    0, 1000); LcdText(1, 0,10, buf);
    sprintf (buf, "%3d %4d  int_Mult",   0, 1010); LcdText(1, 0,20, buf);
    sprintf (buf, "%3d %4d  float_op",   0, 1020); LcdText(1, 0,30, buf);
    sprintf (buf, "%3d %4d  randomize",  0, 1030); LcdText(1, 0,40, buf);
    sprintf (buf, "%3d %4d  matrx_algb", 0, 1040); LcdText(1, 0,50, buf);
    sprintf (buf, "%3d %4d  arr_sort",   0, 1050); LcdText(1, 0,60, buf);
    sprintf (buf, "%3d %4d  displ_txt",  0, 1060); LcdText(1, 0,70, buf);
    sprintf (buf, "%3d %4d  testing...", 0, 1070); LcdText(1, 0,80, buf);

  }
  return 99;
}


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

    LcdClearDisplay();

    CircleOut(50, 40, 10);
    CircleOutEx(30, 24, 10, DRAW_OPT_FILL_SHAPE);
    LineOut(10, 10, 60, 60);
    LineOut(50, 20, 90, 70);
    RectOut(20, 20, 40, 40);
    RectOutEx(65, 25, 20, 30, DRAW_OPT_FILL_SHAPE);
    EllipseOut(70, 30, 15, 20);

  }
  return x;
}


inline void displayValues() {

  char buf[120];

    sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); LcdText(1, 0,10, buf);
    sprintf (buf, "%3d %4d  int_Mult",   1, runtime[1]); LcdText(1, 0,20, buf);
    sprintf (buf, "%3d %4d  float_op",   2, runtime[2]); LcdText(1, 0,30, buf);
    sprintf (buf, "%3d %4d  randomize",  3, runtime[3]); LcdText(1, 0,40, buf);
    sprintf (buf, "%3d %4d  matrx_algb", 4, runtime[4]); LcdText(1, 0,50, buf);
    sprintf (buf, "%3d %4d  arr_sort",   5, runtime[5]); LcdText(1, 0,60, buf);
    sprintf (buf, "%3d %4d  displ_txt",  6, runtime[6]); LcdText(1, 0,70, buf);
    sprintf (buf, "%3d %4d  graphics",   7, runtime[7]); LcdText(1, 0,80, buf);
}


void Handler(int sig)               /// ???
{
  //printf("handler %d\n", sig);    /// ???
}

int main(){

  unsigned long time0, x, y;
  float s;
  char  buf[120];
  int   i;

  SetTimerCallback(ti1sec, &Handler); /// ???

  ClearTimer(0);
  ClearTimerMS(0);

  ButtonLedInit();
  LcdInit();
  LcdClean();


  LcdText(1, 0,10, "hw brickbench");
  LcdText(1, 0,20, "(C)H.Wunder 2013");
  LcdText(1, 0,50, "initializing...");

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


  LcdClearDisplay();

  time0= TimerMS(0);;
  s=test_Int_Add();
  runtime[0]=TimerMS(0)-time0;
  sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); LcdText(1, 0,10, buf);

  time0=TimerMS(0);
  s=test_Int_Mult();
  runtime[1]=TimerMS(0)-time0;
  sprintf (buf, "%3d %4d  int_Mult",   0, runtime[1]); LcdText(1, 0,20, buf);

  time0=TimerMS(0);
  s=test_float_math();
  runtime[2]=TimerMS(0)-time0;
  sprintf (buf, "%3d %4d  float_op",   0, runtime[2]); LcdText(1, 0,30, buf);

  time0=TimerMS(0);
  s=test_rand_MT();
  runtime[3]=TimerMS(0)-time0;
  sprintf (buf, "%3d %4d  randomize",  0, runtime[3]); LcdText(1, 0,40, buf);

  time0=TimerMS(0);
  s=test_matrix_math();
  runtime[4]=TimerMS(0)-time0;
  sprintf (buf, "%3d %4d  matrx_algb", 0, runtime[4]); LcdText(1, 0,50, buf);


  time0=TimerMS(0);
  s=test_Sort();
  runtime[5]=TimerMS(0)-time0;
  sprintf (buf, "%3d %4d  arr_sort",   0, runtime[5]); LcdText(1, 0,60, buf);

  time0=TimerMS(0);
  s=test_TextOut();
  runtime[6]=TimerMS(0)-time0;
  LcdClearDisplay();
  displayValues();

  time0=TimerMS(0);
  s=test_graphics();
  runtime[7]=TimerMS(0)-time0;
  LcdClearDisplay();
  displayValues();


  LcdText(1, 0,100, "cont: press btn < LEFT...");

  while(ButtonWaitForAnyPress(100) != BUTTON_ID_LEFT);

  LcdClearDisplay();
  y=0;
  for(x=0;x<8;++x) {y+= runtime[x];}

  sprintf (buf, "gesamt ms: %d ", y);           LcdText(1, 0,10, buf);
  sprintf (buf, "benchmark: %d ", 50000000/y ); LcdText(1, 0,20, buf);

  LcdText(1, 0,40, "quit: press btn < LEFT...");   // <<<<<<<<< no reaction, just for left + ESC !

  while(ButtonWaitForAnyPress(100) != BUTTON_ID_LEFT);

  LcdExit();
  ButtonLedExit();
  return 1;

}


########################################################################################################


NXT + BCC + NXC:

Code: Alles auswählen

// hw brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: NXC, Enhanced Firmware 2013
// Autor: (C) Helmut Wunder 2013,2014
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach schriftlicher 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.1

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

//--------------------------------------------
// Mersenne Twister
//--------------------------------------------
const int N_MTW = 25;
const int M_MTW = 7;
const unsigned long A_MTW[] = {0, 0x8ebfd028};

unsigned long y_MTW[25];
int i_MTW;
char virgin_MTW=TRUE, new_MTW=FALSE;

void InitMTW() {
  i_MTW = N_MTW+1;
}


unsigned long randM(void) {
  unsigned long r, s, e;
  int k;

  if (virgin_MTW) {virgin_MTW=FALSE; InitMTW(); }

  if (i_MTW >= N_MTW) {
      if ((i_MTW > N_MTW) && !new_MTW) {
         r = 9;
         s = 3402;
         for (k=0 ; k<N_MTW ; ++k) {
           r = 509845221 * r + 3;
           s *= s + 1;
           y_MTW[k] = s + (r >> 10);
         }
      }
      for (k=0 ; k<N_MTW-M_MTW ; ++k)
         y_MTW[k] = y_MTW[k+M_MTW] ^ (y_MTW[k] >> 1) ^ A_MTW[y_MTW[k] & 1];
      for (; k<N_MTW ; ++k)
         y_MTW[k] = y_MTW[k+(M_MTW-N_MTW)] ^ (y_MTW[k] >> 1) ^ A_MTW[y_MTW[k] & 1];
      i_MTW = 0;
  }

  new_MTW=false;
  e = y_MTW[i_MTW++];
  e ^= (e << 7)  & 0x2b5b2500;
  e ^= (e << 15) & 0xdb8b0000;
  e ^= (e >> 16);
  return e;
}

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

#define ArrayInit2D(array, tmp, init_val, dimx, dimy) { \
  ArrayInit(tmp, init_val, dimy);  \
  ArrayInit(array, tmp, dimx);     \
  ArrayInit(tmp,0,0);              \
}


void MatrixMatrixMult(float A[][], float B[][], float &C[][], int N, int M, int K){
  int i, j, s;                  // matrix A: N x M // B: M x K // C: N x K
  float tmp[];
  ArrayInit2D(C,tmp, 0, N, 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];
      }
    }
  }
}




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


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


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



//--------------------------------------------
// 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;
   long s=0;
   for(int 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() {

  long s;

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

  }
  return s;
}

float test_float_math() {

  float s=PI;
  int y;

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


long test_rand_MT(){
  unsigned long s;

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


float test_matrix_math() {
  float A[2][2], B[2][2], C[2][2];
  float O[3][3], T[3][3];
  unsigned long s;

  for(int 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(A,B,C, 2,2,2);

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

    MatrixDet2x2(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;

    MatrixDet3x3(O);

  }

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


long test_Sort(){
  int y;

  for(y=0;y<30;++y) {
    ArraySort(t, a, NA, NA);
    ArraySort(t, b, NA, NA);
    ArraySort(t, c, NA, NA);
  }
  return y;
}



long test_TextOut(){
  unsigned long s;

  for(int y=0;y<20;++y) {
    ClearScreen();
    NumOut(0,56, 0); NumOut(12,56, 1000); TextOut(44,56, "int_Add");
    NumOut(0,48, 1); NumOut(12,48, 1010); TextOut(44,48, "int_Mult");
    NumOut(0,40, 2); NumOut(12,40, 1020); TextOut(44,40, "float_op");
    NumOut(0,32, 3); NumOut(12,32, 1030); TextOut(44,32, "randomize");
    NumOut(0,24, 4); NumOut(12,24, 1040); TextOut(44,24, "matrx_algb");
    NumOut(0,16, 5); NumOut(12,16, 1050); TextOut(44,16, "arr_sort");
    NumOut(0, 8, 6); NumOut(12, 8, 1060); TextOut(44, 8, "displ_txt");
    NumOut(0, 0, 7); NumOut(12, 0, 1070); TextOut(44, 0, "testing...");  Wait(20);
                                                                   // sum=20*20
  }
  return 99;
}


long test_graphics(){
  int x;
  for(int y=0;y<100;++y) {
    ClearScreen();
    CircleOut(50, 40, 10);
    CircleOut(30, 24, 10, DRAW_OPT_FILL_SHAPE);
    LineOut(10, 10, 60, 60);
    LineOut(50, 20, 90, 70);
    RectOut(20, 20, 40, 40);
    RectOut(65, 25, 20, 30, DRAW_OPT_FILL_SHAPE);
    EllipseOut(70, 30, 15, 20);                    Wait(20);
                                                   // sum=20*100
  }
  return x;
}


void displayValues() {
    NumOut(0,56, 0); NumOut(12,56, runtime[0]); TextOut(44,56, "int_Add");
    NumOut(0,48, 1); NumOut(12,48, runtime[1]); TextOut(44,48, "int_Mult");
    NumOut(0,40, 2); NumOut(12,40, runtime[2]); TextOut(44,40, "float_op");
    NumOut(0,32, 3); NumOut(12,32, runtime[3]); TextOut(44,32, "randomize");
    NumOut(0,24, 4); NumOut(12,24, runtime[4]); TextOut(44,24, "matrx_algb");
    NumOut(0,16, 5); NumOut(12,16, runtime[5]); TextOut(44,16, "arr_sort");
    NumOut(0, 8, 6); NumOut(12, 8, runtime[6]); TextOut(44, 8, "displ_txt");
    NumOut(0, 0, 7); NumOut(12, 0, runtime[7]); TextOut(44, 0, "graphics");
}


task main(){

  unsigned long time0, x, y;
  float s;

  TextOut(0,56, "hw brickbench");
  TextOut(0,48, "(C)H.Wunder 2013");
  TextOut(0,32, "initializing...");

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

  ClearScreen();

  time0=CurrentTick();
  s=test_Int_Add();
  runtime[0]=CurrentTick()-time0;
  NumOut(0,56, 0); NumOut(12,56, runtime[0]); TextOut(44,56, "int_Add");

  time0=CurrentTick();
  s=test_Int_Mult();
  runtime[1]=CurrentTick()-time0;
  NumOut(0,48, 1); NumOut(12,48, runtime[1]); TextOut(44,48, "int_Mult");

  time0=CurrentTick();
  s=test_float_math();
  runtime[2]=CurrentTick()-time0;
  NumOut(0,40, 2); NumOut(12,40, runtime[2]); TextOut(44,40, "float_op");

  time0=CurrentTick();
  s=test_rand_MT();
  runtime[3]=CurrentTick()-time0;
  NumOut(0,32, 3); NumOut(12,32, runtime[3]); TextOut(44,32, "randomize");

  time0=CurrentTick();
  s=test_matrix_math();
  runtime[4]=CurrentTick()-time0;
  NumOut(0,24, 4); NumOut(12,24, runtime[4]); TextOut(44,24, "matrx_algb");

  time0=CurrentTick();
  s=test_Sort();
  runtime[5]=CurrentTick()-time0;
  NumOut(0,16, 5); NumOut(12,16, runtime[5]); TextOut(44,16, "arr_sort");

  time0=CurrentTick();
  s=test_TextOut();
  runtime[6]=CurrentTick()-time0-(20*20); // minus wait states
  ClearScreen();
  displayValues();

  time0=CurrentTick();
  s=test_graphics();
  runtime[7]=CurrentTick()-time0-(20*100); // minus wait states
  ClearScreen();
  displayValues();

  getchar();

  ClearScreen();
  y=0;
  for(x=0;x<8;++x) {y+= runtime[x];}

  TextOut(0,56, "gesamt ms:"); NumOut(66,56, y);
  TextOut(0,40, "benchmark:"); NumOut(66,40, 50000000/y);

  TextOut(0, 8, "quit: press btn...");

  getchar();

}



########################################################################################################


NXT + nxtOSEK: nxtOSEK TOPPERS/ATK C/C++

Code: Alles auswählen

// hw brickbench
// benchmark test for NXT
// PL: nxtOSEK TOPPERS/ATK C/C++
// Autor: (C) Helmut Wunder 2013, 2014
// Ported to nxtOSEK by Martin Aumair
// http://roboticsaumair.jimdo.com/
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach schriftlicher Genehmigung durch den Autor.
// version 1.09.1 release 2014-08

// Runs only on nxtBios (RAM+ROM)

extern "C" {
#include "../../../toppers_osek/include/kernel.h"
#include "kernel_id.h"
#include "../../../ecrobot/c/ecrobot_interface.h"
#include "../../../lejos_nxj/src/nxtvm/platform/nxt/mytypes.h"
}

#include "../../../NXtpandedLib/src/NLine.hpp"
#include "../../../NXtpandedLib/src/NRectangle.hpp"
#include "../../../NXtpandedLib/src/NCircle.hpp"
#include "../../../NXtpandedLib/src/NEllipse.hpp"

#include "../../../../GNUARM/arm-elf/sys-include/math.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////OSEK HOOKS/IRS///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

extern "C" {

// nxtOSEK hook to be invoked from an ISR in category 2
void user_1ms_isr_type2(void) { }

// hooks
void ecrobot_device_initialize(void);
void ecrobot_device_terminate(void);

bool btnhit() {
   return (ecrobot_is_RUN_button_pressed() || ecrobot_is_ENTER_button_pressed());
}

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

int a[500], b[500], c[500];

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

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


void MatrixMatrixMult(int N, int M, int K, float A[][2], float B[][2], float C[][2]) {
   int i, j, s;
   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];
         }
      }
   }
}



// no VLA!
float MatrixDet(int N, float A[]) {
   int i, j, i_count, j_count, count = 0;
   float Asub[N - 1][N - 1], det = 0;

   if (N == 1)
      return *A;
   if (N == 2)
      return ((*A) * (*(A+1+1*N)) - (*(A+1*N)) * (*(A+1)));

   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*N);
            j_count++;
         }
         i_count++;
      }
      det += pow(-1, count) * A[0+count*N] * MatrixDet(N - 1, &Asub[0][0]);
   }
   return det;
}


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

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 = (unsigned int) (increment / 2.2);
  }
}


//--------------------------------------------
// 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;
}


double test_float_math() {

  volatile double s=PI;
  int y;

  for(y=0;y<1000;++y) {
     s*=sqrt(s);
     s=sin(s);
     s=exp(s);
     s*=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;

      MatrixDet(2, &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;

      MatrixDet(3, &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;
}


// helper functions for output
// normally with cout our sprintf but I think in a benchmark we take the fastest method
void NumOut(int x, int y, int num, U32 places) {
   display_goto_xy(x, y);
   display_int(num, places);
}

void TextOut(int x, int y, const char *str) {
   display_goto_xy(x, y);
   display_string(str);
}

long test_TextOut() {
   int y;

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

      // x,y value is line not pixel! nxtOSEK use fast dma update in chars,lines!
      NumOut(0,0, 0, 1); NumOut(2,0, 1000, 4); TextOut(8,0, "int_Add");
      NumOut(0,1, 1, 1); NumOut(2,1, 1010, 4); TextOut(8,1, "int_Mult");
      NumOut(0,2, 2, 1); NumOut(2,2, 1020, 4); TextOut(8,2, "float_op");
      NumOut(0,3, 3, 1); NumOut(2,3, 1030, 4); TextOut(8,3, "rand_array");
      NumOut(0,4, 4, 1); NumOut(2,4, 1040, 4); TextOut(8,4, "matrx_algb");
      NumOut(0,5, 5, 1); NumOut(2,5, 1050, 4); TextOut(8,5, "arr_sort");
      NumOut(0,6, 6, 1); NumOut(2,6, 1060, 4); TextOut(8,6, "displ_txt");
      NumOut(0,7, 7, 1); NumOut(2,7, 1070, 4); TextOut(8,7, "testing...");
      display_update();  // not really good because we can update hardware only every 16 ms
   }
   return 99;
}

using namespace nxpl; // NXtpandedLib
NLcd lcd;

long test_graphics() {
   int x = 0;
   for (int y = 0; y < 100; ++y) {
     lcd.clear();
      // no official functions, its my actual project: NXtpandedLib
      NCircle::draw(NPoint(50, 40), 10);
      NCircleFilled::draw(NPoint(30, 24), 10);
      NLine::draw(NPoint(10, 10), NPoint(60, 60));
      NLine::draw(NPoint(50, 20), NPoint(90, 70));
      NRectangle::draw(NPixelBox(NPoint(20, 20), 40, 40));
      NRectangleFilled::draw(NPixelBox(NPoint(65, 25), 20, 30));
      NEllipse::draw(NPoint(70, 30), 15, 20);

      NLcd::update(); // not really good because we can update hardware only every 16 ms
   }
   return x;
}



U32 runtime[8];

void displayValues() {
   display_clear(0);

   NumOut(0,0, 0, 1); NumOut(2,0, (int)runtime[0], 5); TextOut(8,0, "int_Add");
   NumOut(0,1, 1, 1); NumOut(2,1, (int)runtime[1], 5); TextOut(8,1, "int_Mult");
   NumOut(0,2, 2, 1); NumOut(2,2, (int)runtime[2], 5); TextOut(8,2, "float_op");
   NumOut(0,3, 3, 1); NumOut(2,3, (int)runtime[3], 5); TextOut(8,3, "rand_array");
   NumOut(0,4, 4, 1); NumOut(2,4, (int)runtime[4], 5); TextOut(8,4, "matrx_algb");
   NumOut(0,5, 5, 1); NumOut(2,5, (int)runtime[5], 5); TextOut(8,5, "arr_sort");
   NumOut(0,6, 6, 1); NumOut(2,6, (int)runtime[6], 5); TextOut(8,6, "displ_txt");
   NumOut(0,7, 7, 1); NumOut(2,7, (int)runtime[7], 5); TextOut(8,7, "grafics");
}

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


TASK(TaskMain) {
   //test_graphics();
   //display_update();


   unsigned long time0, x, y;
   float s;

   display_clear(1);

   TextOut(0, 0, "hw brickbench");
   TextOut(0, 1, "(C)H.Wunder 2013");
   TextOut(0, 3, "nxtOSEK port:");
   TextOut(0, 4, "Martin Aumair");
   TextOut(0, 5, "initializing...");
   display_update();
   systick_wait_ms(3000);

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

   TextOut(0, 6, "done .. go!");
   display_update();
   systick_wait_ms(2000);
   display_clear(1);

   time0 = systick_get_ms();
   s = test_Int_Add();
   runtime[0] = systick_get_ms() - time0;
   NumOut(0,0, 0, 1); NumOut(2,0, (int)runtime[0], 5); TextOut(8,0, "int_Add");
   display_update();

   time0 = systick_get_ms();
   s = test_Int_Mult();
   runtime[1] = systick_get_ms() - time0;
   NumOut(0,1, 1, 1); NumOut(2,1, (int)runtime[1], 5); TextOut(8,1, "int_Mult");
   display_update();

   time0 = systick_get_ms();
   s = test_float_math();
   runtime[2] = systick_get_ms() - time0;
   NumOut(0,2, 2, 1); NumOut(2,2, (int)runtime[2], 5); TextOut(8,2, "float_op");
   display_update();

   time0 = systick_get_ms();
   s = test_rand_MT();
   runtime[3] = systick_get_ms() - time0;
   NumOut(0,3, 3, 1); NumOut(2,3, (int)runtime[3], 5); TextOut(8,3, "rand_array");
   display_update();

   systick_wait_ms(1500);

   time0 = systick_get_ms();
   s = test_matrix_math();
   runtime[4] = systick_get_ms() - time0;
   NumOut(0,4, 4, 1); NumOut(2,4, (int)runtime[4], 5); TextOut(8,4, "matrx_algb");
   display_update();

   systick_wait_ms(1500);

   time0 = systick_get_ms();
   s = test_Sort();
   runtime[5] = systick_get_ms() - time0;
   NumOut(0,5, 5, 1); NumOut(2,5, (int)runtime[5], 5); TextOut(8,5, "arr_sort");
   display_update();

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


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

   displayValues();

   while (! btnhit() );  //  <<<<< wait for btnpress

   display_clear(1);
   y = 0;
   for (x = 0; x < 8; ++x) {
      y += runtime[x];
   }

   TextOut(0,0, "sum ms:");    NumOut(8,0, y, 7);
   TextOut(0,1, "benchmark:"); NumOut(8,1, 50000000/y, 7);

   systick_wait_ms(1000);
   while (! btnhit() );  //  <<<<< wait for btnpress

   TerminateTask();
}

}




########################################################################################################

NXT + RobotC 3.62

Code: Alles auswählen

// hw brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: ROBOTC 3.62 for NXT
// Autor: (C) Helmut Wunder 2013,2014
// Ported to ROBOTC by Xander Soldaat
// http://botbench.com
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach schriftlicher 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.1


/////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////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;
}


double test_float_math() {

  volatile double s=PI;
  int y;

  for(y=0;y<1000;++y) {
     s*=sqrt(s);
     s=sin(s);
     s=exp(s);
     s*=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();
}




(Forts. folgt!)

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 20. Apr 2014 09:47

hier jetzt auch die Source Codes für leJOS (NXT + EV3) und RobotC 4.x (EV3):


########################################################################################################

hw brickbench benchmark für NXT für leJOS/Java:

Code: Alles auswählen

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 schriftlicher 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();
    }
}


########################################################################################################

hw brickbench benchmark für EV3 für leJOS/Java:

Code: Alles auswählen

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.8.0-alpha
// Autor: (C) Helmut Wunder 2013,2014
// Ported to leJOS by Andy Shaw.
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach schriftlicher 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

// 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();
    }

}


########################################################################################################


hw brickbench benchmark für RobotC 4.0x-alpha für EV3:

Code: Alles auswählen

// hw brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: ROBOTC 4.0x-alpha
// Autor: (C) Helmut Wunder 2013,2014
// Ported to ROBOTC by Xander Soldaat
// http://botbench.com
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach schriftlicher 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.1-alpha


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

int a[500], b[500], c[500], t[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 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 = (unsigned int) ((float)increment / 2.2);
//  }
//}





//--------------------------------------------
// 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 < 1000; ++y) {
      s *= sqrt(s);
      s = sin(s);
      s = exp(s);
      s *= 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;


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

  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();

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

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


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

   eraseDisplay();

   writeDebugStreamLine("HaWe_Bench");
   writeDebugStreamLine("(C)H.Wunder 2013");
   writeDebugStreamLine("ROBOTC port:");
   writeDebugStreamLine("Xander Soldaat");
   writeDebugStreamLine("initializing...");

   //wait1Msec(3000);

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

   writeDebugStreamLine("done .. go!");
   wait1Msec(2000);
   eraseDisplay();

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

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

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

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

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

   time0 = nSysTime;
   s = test_Sort();
   runtime[5] = nSysTime - time0;
   writeDebugStreamLine("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];
   }

   writeDebugStreamLine("sum ms: %d", y);
   writeDebugStreamLine("benchmark: %d", 50000000/y);
   while (true) sleep(1);
}



########################################################################################################

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench Benchmark Test für NXT, EV3 & andere CPUs

Beitragvon HaWe » 14. Mai 2014 21:59

########################################################################################################
HaWe Brickbench Benchmark Test

Setup + design:
This benchmark test is including several test functions for different individual computational patterns:
- simple basic integer arithmetics (addition/substraction, multiplication/division),
- real and transcendental float arithmetic functions (sqrt, sin, exp, x²), preferably 64bit double (=> bonus points)
- advanced matrix algebra for more-dim array manipulation (matrix product + determinant, built-in or imported) (genuine multi-dim arrays => bonus points)
- pseudo random number generator (Mersenne Twister): low-level bit- and-byte-operations like AND, XOR, SHIFT-left/right
- quick high-level sort algorithm for arrays[500] (preferably Shellsort, built-in or imported),
- a text-output and a 2D-graphics test for graph + shape + fill computation and lcd output stressing.

the latest brickbench test enhancement also takes programming-environments into account, i.e.
- available memory, networking/chaining abilities,
- variable types (e.g. for double precision fp and matrices/more-dim arrays),
- recursions,
- multithreading support,
- and, last but not least, the wholeness of API functions for hardware (screen, and attached sensors and motors), and the IDE.

Code reference: http://www.mindstormsforum.de/viewtopic.php?f=71&t=8095&p=64494#p64494

If anyone should encounter errors, bugs, or missing data: please report!

remark: a bug had been reported to the float_math benchmark where NANs have been generated; in that case some programming platformes falsely seemed to work faster than they actually really worked. The code is now corrected and adapted.
fixed code not tested yet for leJOS/NXT and RobotC(NXT+EV3), but fixed and tested for all the other platforms.


########################################################################################################
Ergebnisse / Results: Mindstorms Bricks (Version 1.53)

Code: Alles auswählen

HaWe brickbench © test (time: ms)        NXT        NXT     NXT        NXT         EV3       EV3       EV3        EV3       EV3       
MCU, cpu-Takt                              ARM7/48MHz         ARM7/48MHz            ARM9/300MHz         ARM9/300MHz     ARM9/300MHz
progr.language, API                      NXC      RobotC   leJOS   T/ATK C++    BCC/gpp C   leJOS     RobotC    C#/Mono  EV3-Basic   
Firmware / vers.                     JH's EFW      3.6     0.9.1  nxtOSEK BIOS   LegoFW**) (loop1-6)  4.0.x    (loop1-5)  LegoFW     
screen size (b/w)                      100x64    100x64    100x64    100x64       178x128   178x128   178x128   178x128   178x128   
=====================================================================================================================================
 0 100000 integer add/subtr             3352      1561      727        29           3      1 - 70      336        1- 16       611       
 1 52000 integer multiply/division      6441      1150      463       182          13     10 - 83      589       25- 67       909     
 2 5000 transc. float operations         423     ( 413)   (2543)      409***)      61     48 -171    ( 226)     227-245       148     
 3 MersenneTw.PRNG(bit-alg.) (N/A:max+) 5371      1838       73        55           4      5 - 15     1204       12- 18     [6000]---   
 4 matrix algebra (prod/determ.)        3344       585       68        39          10      45-156      325       40-230       409       
 5 int array sort [500]                  332     95879    18756       491         113     127-193    20932      150-176     18660     
.....................................................................................................................................
interm. time                          19,263   101,426   22,630     1,205         204     236-688   ?-23612-?   455-752     26737
.....................................................................................................................................
 6 display text (N/A:penalty max+)       730        32       26        17          28     171-275    [ 800]---  219-333       219     
 7 display graphics *)                   301      ?(95)?  11480       182          51      37-708   [12000]---  158-302       278     
=====================================================================================================================================
execution time                        20,294   101,553   34,136     1,404         283    444-1671  ?-36412-?   832-1387     27234     
=====================================================================================================================================
10 flash+SD r/w(score=ln^3,max.1000)120k(110) 112k(105)      ?   224k(158)   <=5M(750)       ?           ?     <16M(900) <=5M(750)   
11 variable mem.   (score= ln^3)      32k(42)   15k(20)      ?     64k(72)  <64M(1300)       ?       15k(20)   42M(1200) 40M(1200) 
12 external non-volat. mem. (SD=100)       0         0       ?          ?         100       100         100         100       100     
13 max analog/UART/i2c/dig.Sensors (x10)  80        80      80         80        ---0---     40          40          40        40       
14 max Encoder Motors + pwm (x10)         30        30      30         30          40        40          40          40        40   
15 BT raw master+slave   (score 10x)   4 (40)    2 (20)      ?      2 (20)          0        +           ?          100         ?     
16 BT   Daisy-Chain      (score 50x)       0         0       ?          0           0       400          ?            ?         0     
17 ser. Daisy-Chain      (score 50x)       0         0       ?          0           0        +           ?            ?         ?   
18 USB  Daisy-Chain      (score 50x)       0         0       ?          0           0       200          ?            ?       200   
19 WiFi Daisy-Chain      (score 50x)       0         0       ?          0           0       800          ?            ?         ?   
20 double=64bit float (score 100)          0         0      100         0         100       100          0          100         0   
21 >=4D array op.     (score 100)        100         0       ?          0         100        ?           0          100         ?   
22 Recursions      (score 100)             0       100      100       100         100       100        100          100       100   
23 Multitthreading(preempt.500/coop.200) 500       500      500       500         500       500        500          500       200   
24 API complete (sensor+motor+screen)      +         +       +        (+)         ---        +          +             +         +   
25 small downstripped IDE (score 500)    500       500       0          0         500        0         500            0       500   
26 setup.exe for install & auto-config   500       500       0          0         250        0         500            0       500     
=====================================================================================================================================
Brick platform                           NXT       NXT     NXT        NXT        EV3       EV3         EV3         EV3        EV3     
progr.language, Firmware                 NXC     RobotC   leJOS     nxtOSEK   BCC/gpp C   leJOS       RobotC      C#/Mono   EV3-Basic 
=====================================================================================================================================
  minimum preformance  (50,000,000/ms)                                                   29,400-                  36,049-
max. speed bench score (50,000,000/ms)  2463      485    1,423     35,613     184,000    67,200     ?-1,373-?     60,096       
 
environnment bench score               1,902    1,855   ? ,810     ,960         [---0]   2,280        1,800        3,180     3,630     
-------------------------------------------------------------------------------------------------------------------------------------
brickbench system benchmark min.       4,365    2,340-?  2,233-? 36,573  [---184,000]   31,680      ?-3,173-?     39,229     5,468   
brickbench system benchmark max.       4,365    2,340-?  2,233-? 36,573  (devaluated)   69,480      ?-3,173-?     63,276     5,468 
=====================================================================================================================================


Code: Alles auswählen

 
[color=#FF0000][b][u]Ergebnisse / Results: diverse MCUs [/u] [/b][/color]
[code]
HaWe brickbench © test (time: ms)     Arduino         Arduino         Arduino     PJRC Teensy   Raspberry Pi   
Typ, OS, FW, PL, API                  Mega2560          Due             Zero          3.1     B+(2B)/Raspbian
MCU, cpu-Takt                        AVR/16MHz      ARM M3/84Mhz    ARM M0/48MHz  ARM M4/72MHz   800-1000MHz
Firmware/vers.,Pr.Lang.            IDE 1.6x C++     IDE 1.6x C++    IDE 1.6x C++  IDE 1.6x C++  gnu C++, Geany
LCD / TFT (true color)             ILI9225 UTFT    ILI9341_due   (Adafr.ILI9340)  ILI9327 NC    HDMI,full-HD
screen size tested                    240*176         320*240         320*240       320*240       1024*600
==============================================================================================================
 0 100000 integer add/subtr                129            8              15            5             1
 1 52000 integer multiply/division        1219            7             102            5             3
 2 5000 transc. float operations           326          107             397           92         (2)-13
 3 Mersenne Tw. PRNG (&,^,>>,<<)           313            7              36            4             2
 4 matrix algebra (prod/determ.)           244           23              92           19             1
 5 int array sort [500]                   1366          171             379          110       (46)-88
..............................................................................................................
interm.   time                            3415          323            1021          235       (53)-108
..............................................................................................................
 6 display text                          80618          973     (~DUE: 9200)        1667          2630     
 7 display graphics                     224505         3255     (~DUE:41000)        3194         13333   
==============================================================================================================
execution time                          308720         4551           51221         5096         16072
==============================================================================================================
10 flash read/write(score= ln^3)     (248k)160    (512k)240       (256k)160    (256k)160             0
11 variable mem.   (score= ln^3)       (8k)  8     (96k) 95        (32k) 42    ( 64k) 72    (512M)2000
12 external non-volat. mem. (SD=100)       100          100             100          100           100
13 max. Sensors (max:=100) (score 10x)    1000         1000            1000         1000            70-100(IO shields: inf.)         
14 max Encoder Motors + pwm (x10)           80           80              20           40            20         
15 BT raw master+slave   (score 10x)         0            0               0            0             0
16 BT   Daisy-Chain     (score 50x)          0            0               0            0             0
17 ser. Daisy-Chain      (score 50x)         0            0               0            0             0-1600(BrickPi3=8*4)
18 USB  Daisy-Chain     (score 50x)          0            0               0            0             0
19 WiFi Daisy-Chain     (score 50x)          0            0               0            0             0
20 double=64bit float (score 100)            0          100             100          100           100
21 >=4D array op.  (score 100)               0            0               0            0           100
22 Recursions      (score 100)             100          100             100          100           100
23 Multitthreading(preempt.500/coop.200)   200          200             200          200           500
24 API complete (sensor+motor+screen        +            +               +            +             +
25 small downstripped IDE (score 500       500          500             500          500           500
26 setup.exe for install & auto-config     500          500             500          500           500
=====================================================================================================================
Brick platform                        Ardu.2560     Ardu.Due         Ard.Zero      Teensy      Raspberry Pi
progr.language, Firmware                C/C++          C/C++           C/C++        C/C++         C/C++
=====================================================================================================================
speed bench score (50,000,000/ms)         ,162        10,997            ,976        9,812        3,111
environnment bench score                 2,488         2,915           2,722        2,772        3,990-5620
---------------------------------------------------------------------------------------------------------------------
brickbench system benchmark              2,650        13,912           3,698       12,584        7,101-7731(BrickPi3)
=====================================================================================================================




Notes:
© Helmut Wunder 2013-2017.
HaWe brickbench test Comparison tables/spreadsheets and results are copyright protected and must not be freely created, copied and / or distributed. Additions and / or changes in the tables require written permission by the author. The test source code is Open Source and protected under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License http://creativecommons.org/licenses/by-nc-sa/3.0/ and is free for private usage.
Of course your own determined data are very much appreciated - feel free to send them to me and I'll integrate them into the comparison spreadsheet to keep everything updated!

HaWe brickbench test - Vergleichstabellen und Ergebnisse sind urheberrechtlich geschützt und dürfen nicht frei erstellt, kopiert und/oder verbreitet werden. Ergänzungen und/oder Veränderungen der Tabellen bedürfen der schriftlichen Genehmigung durch den Autor. Der Test Programmcode ist jedoch Open Source und veröffentlicht unter der Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License http://creativecommons.org/licenses/by-nc-sa/3.0/ und darf frei für private Zwecke verwendet werden.
Ich freue mich aber natürlich über eure ermittelten Daten - sendet sie mir einfach und ich integriere sie in die Vergleichstabelle, um sie aktuell zu halten!

tests by RobotC, leJOS, C#, and ev3dev source codes have been performed by external developers and have not been independently confirmed by me or different users. Some of these data perhaps have to be corrected.
Additional testers for either platforms would be appreciated!
missing data sets have been already requested about [b]RobotC and leJOS but no reply yet.
some leJOS code issues have been reported to Andy Shaw

source codes see above and below![/b]
daisy-chain = comparable to EV3-USBdaisy-chaining
?) some benchmarks or data partially missing
about leJOS and/or C#Mono: measures taken: always the best and the worst runs of 1-6, either by AOT or JIT compilers
*) external graphic libs, multithreading libs:
- RobotC TextOut is implausible! (Quicker than nxtOSEK ?!?)
· RobotC graphic test not quite trustworthy: probably not faster than nxtOSEK executables!
· nxtOSEK: https://github.com/martin-au/NXtpandedLib/blob/master/LcdDrawer.hpp,
· Mono/C# graphic libs: https://github.com/vladru/MonoBrickBench;
· ILI9341_due lib: https://github.com/marekburiak/ILI9341_due
· external multithreading libs for gpp/C: pthread, for Arduino Sketch C: proto threads, mthread, Scheduler, FreeRTOS, ERIKA, OS48, Babix.
**) Lego EV3-G virtual machine running simultaneously, RAM and cpu processing time needed for VM: >> unknown <<
***) nxtOSEK: new float benchmark patch not finally veryfied by different testers
--- GCC/BricxCC: extremely good scores, BUT: sensor API missing (leads to complete devaluation!)
--- EV3-RobotC Display tests: no results available => penalty scores
--- EV3-Basic: Mersenne Twister bit operations not possible => penalty scores
Arduino Mega/Due Flash not usable for non-volatile data memory, file r/w libs shaky (erased during program upload!), but non-volatile SD card memory available
Arduino Zero + Teensy test performed by: http://forum.arduino.cc/index.php?topic ... msg2398429
reference for leJOS double float precision: Andy Shaw (leJOS developer): facebook.com/groups/legomindstorms
reference to C#/Mono data: viewtopic.php?f=71&t=8095&p=65291#p65290



########################################################################################################

Ergebnisse:
Auf dem NXT sind sind die VM-basierten Plattformen (NXC, RobotC, Lejos) extrem unterschiedlich in Einzelkategorien (teilw. Faktor 300x) - was sich aber zum Schluss wieder stark herausmittelt (RobotC schlechteste Performance, NXC beste).
Auf dem NXT ist nxtOSEK bei weitem am schnellsten (benchmark 15-70x (!!) so hoch wie bei VM-Plattformen). Gemessen an Executables entspricht die Leistung gegenüber dem EV3 dem cpu-Takt-Verhältnis.
Auf dem EV3 sind Executables (BCC/gpp C) hat die beste Performance über alles, es folgen fast gleichauf leJOS and Mono C# (1/3 so leistungsstark; etwas langsamer am Anfang, bei häufigeren Wiederholungen schneller).
Dummerweise gibt es für BCC/gpp C keine Sensor-API, sodass es für den Roboterbau komplett nutzlos ist; BCC/C wurde daher abgewertet.
Von der Geschwindigkeit der EV3-Plattformen sind RobotC und EV3Basic die langsamsten, hier bietet allerdings RobotC nur ~15k Speicher für Variablen und kein Daisy-Chaining; künftige Verbesserungen sind aber angeblich geplant...(?).
Die Raspis sind natürlich bei weitem die schnellsten Geräte bezogen auf reine Rechengeschwindigkeit, und der Nachteil durch langsame Displays ist eigentlich unmaßgeblich, da es dank premptivem MT in unabhängige Tasks ausgelagert werden kann.

Results:
On the NXT all VM-based platforms (NXC, RobotC, Lejos) show huge differences in single categories (part. factor 300x) - but finally, all averages out - more or less - (RobotC worst performance, NXC best).
On the NXT nxtOSEK is by far the fastest and most powerful platform (15-70x (!!) as much as the VM platforms). Measured by executables, the performance compared to the EV3 equals the NXT:EV3 cpu clock ratio.
On the EV3 executables (GCC/BricxCC and GCC/ev3dev) have the best over-all performance, next come leJOS and Mono C# (almost on a par, a little slower in the beginning, faster after some iterations ).
Unfortunately, there is for GCC/BricxCC no Sensor API, so that it is completely useless for robot construction; thus results for GCC/BricxCC have been devaluated.
For the EV3, RobotC and EV3Basic are the slowest, but RobotC provides only ~15k memory for variables, and no Daisy-Chaining; future enhancements announced by the devs...(?)
The Pis of course are the fastest devices of all by computational speed, and even the drawback by the slow display performance is actually irrelevant, because that can be outsourced to independent tasks due to pre-emptive MT.


benchmarks wishful but still missing yet for
  • C / NxOS for NXT
  • pbLua for NXT
  • NXT-G and EV3-G
  • gcc für ev3dev, confirmed + reproduced
Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench Benchmark Test für NXT, EV3 & andere CPUs

Beitragvon HaWe » 27. Jul 2014 12:03

ps
nachdem jetzt die Sourcecodes für NXC, RobotC, C (gpp, nxtOSEK, Sketch), C# und Java vorliegen (noch teilw. unvollständig bzw. noch fehlerhaft), fehlen momentan noch komplett:

  • C / NxOS für NXT
  • pbLua für NXT
  • NXT-G und EV3-G (wenn das mit den Bildchen überhaupt geht)
=> Traut sich wer?

Anschlussfragen:
  • wieviel Speicher ist verfügbar für Code und Variablen?
  • Details zur Leistungsfähigkeit der Programmiersprachen
  • wieviele Bricks (NXT. EV3) können verbunden werden (USB, BT, rs485, i2c, WiFi)?

Martin0x5E
Schreibt super viel
Schreibt super viel
Beiträge: 496
Registriert: 17. Dez 2011 11:39
Wohnort: Österreich

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon Martin0x5E » 30. Jul 2014 11:09

nxtOSEK:
Im Flash:
32 Kb : NXT BIOS
224 Kb: Anwender-Programm

SRAM:
64 Kb: Anwender-Programm

Laut Website stehen also 224Kb für das Anwender-Programm zur Verfügung.

Wie genau die Aufteilung zwischen statischen/dynamischen Daten auf die Speicher erfolgt kannst du hier nachlesen:
http://lejos-osek.sourceforge.net/nxtOSEK_hack.htm

Soweit ich das verstanden habe: SRAM für statische Dinge wie Code, Konstanten... und Flash für Variablen, Heap und co.

edited, verschoben:
224Kb max. Speicher für Programmcode gesamt, bestätigt
64 Kb: max. Speicher für Variablen gesamt, angenommen (muss fast so sein)
Projekte und Informationen auf meiner Website: http://roboticsaumair.jimdo.com/

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 31. Jul 2014 18:21

danke für die Bestätigung, so hatte ich es dann schließlich auch interpretiert - und auch in den Benchmark schon genau so reingeschrieben 8-)

Martin0x5E
Schreibt super viel
Schreibt super viel
Beiträge: 496
Registriert: 17. Dez 2011 11:39
Wohnort: Österreich

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon Martin0x5E » 4. Aug 2014 18:10

Fällt mir erst jetzt auf ... RobotC rechnet mit float schneller als mit int?
Ich versteh die Welt nicht mehr :roll: :D
Projekte und Informationen auf meiner Website: http://roboticsaumair.jimdo.com/

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 4. Aug 2014 18:57

hi,
alle Lego-ähnlichen VMs arbeiten intern ausschließlich mit float, soweit ich weiß - haben also gar kein int.
Daher ist dann fp-Arithmetik kein Nachteil mehr gegenüber integer-Arithmetik (im Gegensatz zu richtigen Compilern).
Dieses Phänomen hatte ich sogar schon im Mindboards-Forum beschrieben und diskutiert, leider ist das Forum ja jetzt zerstört (bis auf hoffentlich teilweise intakte und restaurierbare Datenrestbestände... :( )
Außerdem kann man die Anzahl der Rechenoperationen bei int vs. float-benchs nicht gleichsetzen (es sind ja bei den transzendenten Funktionen ganz andere, sehr komplexe Funktionen, deren Werte über Reihenentwicklungen berechnet werden wie z.B. die Taylor-Reihe etc.), und die loop-Counter brauchen ja auch zusätzliche Zeit, obwohl sie gar nicht mitgerechnet werden dürften.
Dann kommt hinzu, dass bei den int-tests 52000 bzw. 100000 Operationen gerechnet werden, bei transzendenten float-Tests aber nur 5000, damit die Gewichtung der Tests untereinander besser ausgeglichen ist.

RobotC hat darüberhinaus noch einen "Beschleuniger", den NXC wohl nicht hat: C-Compiler-typische Syntax wie
++i statt i=i+1
oder
x*=3 anstatt x=x*3
und auch
x<<3 statt x=x*8
hat nach meinen eigenen Beobachtungen (im Unterschied zu NXC) einen bis zu 50%igen Geschwindigkeitsvorteil.

Allerdings ist ja sogar auch NXC von der reinen Stoppzeit her bei float benchs schneller als bei int benchs.
Vllt erklärt das dieses Phänomen...

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5241
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: hw brickbench: Benchmark Test für NXT und EV3

Beitragvon HaWe » 9. Aug 2014 09:11



########################################################################################################

Code für EV3 C# Mono:

Erste ungeprüfte Ergebnisse für C#/Mono (text_out und graphic_out sowie Daten zu Speicher, Vernetzung und API-Features fehlen noch):
(aktuelle Tabelle s. viewtopic.php?f=71&t=8095&start=60#p64772)

Code: Alles auswählen

Integer add/subtr.
Integer mult./div.
Float operations
Rnd.num.generation
Matrix algebra
Arrays shell sort.
 
"Monobrick C#" loop 1
15
35
212
19
229
299

"Monobrick C# loop 3"
2
26
155
13
43
172

"Monobrick C# loop 5"
1
38
158
13
35
152




########################################################################################################

Code: Alles auswählen

// hw brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: C# build by Xamarin Studio 5.2. on runtime Mono 3.3.0
// Autor: (C) Helmut Wunder 2013
// Ported to MonoBrick C# by Vlad Ruzov
//
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach schriftlicher 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.1

// Please be note that code below is not good style c# code.
// It has been ported from C so that the changes were minimal.

using System;
using System.Diagnostics;
using System.Threading;
using MonoBrickFirmware.Display;
using MonoBrickFirmware.UserInput;

namespace BrickBench
{
   public static class Program
   {

      static int[] a = new int[500], b = new int[500], c = new int[500];
      static long[] runtime = new long[8];

      // A[Ra x Ca] * B[Rb x Cb] = C[Ra x Cb]
      // N = Ra
      // M = Ca, Rb
      // K = Cb
      static 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,j] = 0;
               for (s = 0; s < M; ++s) {
                  C[i,j] += A[i,s] * B[s,j];
               }
            }
         }
      }

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

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

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

         int[] A = (int[])sortData.Clone();

         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 = (uint) ((float)increment / 2.2);
         }

         A.CopyTo(sortData, 0);
      }

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

      static void TestIntAdd()
      {
         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 void TestIntMult() {
         int x, y;
         int s = 1;
         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 void TestFloatMath() {
         double s = 3.141592;
         int y;

         for (y = 0; y < 1000; ++y) {
            s *= Math.Sqrt(s);
            s = Math.Sin(s);
            s = Math.Exp(s);
            s *= s;
         }
         //return s;
      }

      static void TestRandMT() {
         uint s;
         int y;

         for (y = 0; y < 5000; ++y) {
            s = RandM.Get() % 10001;
         }
         //return s;
      }

      static void TestMatrixMath() {

         float[,] A = new float[2,2];
         float[,] B = new float[2,2];
         float[,] C = new float[2,2];
         float[,] O = new float[3,3];
         float s = 0;

         int x;
         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[1,0] = 30;
            B[0,1] = 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;

            s = MatrixDet2x2(A);

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

            s = MatrixDet3x3(O);
            // s must be 74
            // http://www.wikihow.com/Find-the-Determinant-of-a-3X3-Matrix
         }

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

      static void TestSort()
      {
         int[] t = new int[500];
         int y;
         //int i;
         for(y=0;y<30;++y) {
            //memcpy(t, a, sizeof(a));
            //for(i=0; i<500;++i) {t[i]=a[i];}
            a.CopyTo(t, 0);
            shellsort(500, t);
            //memcpy(t, b,  sizeof(a));
            //for(i=0; i<500;++i) {t[i]=b[i];}
            b.CopyTo(t, 0);
            shellsort(500, t);
            //memcpy(t, c,  sizeof(a));
            //for(i=0; i<500;++i) {t[i]=c[i];}
            c.CopyTo(t, 0);
            shellsort(500, t);
         }
      }

      static void displayValue(int testNo, long testTime, String testName)
      {
         LcdConsole.WriteLine ("{0:D1}: {1} - {2} ms", testNo, testName.PadRight(10), testTime);
      }

      public static void Main (string[] args)
      {
         LcdConsole.Clear();
         LcdConsole.WriteLine ("hw brickbench. (C)H.Wunder 2013");
         LcdConsole.WriteLine ("initializing...");

         int i;
         for (i = 0; i < 500; ++i)
         {
            a[i] = RandM.GetIntValue() % 30000;
            b[i] = RandM.GetIntValue() % 30000;
            c[i] = RandM.GetIntValue() % 30000;
         };

         while (!bEscapeIsPressed)
         {
            DoTest (0, "Int_Add", TestIntAdd);
            DoTest (1, "Int_Mult", TestIntMult);
            DoTest (2, "Float_Op", TestFloatMath);
            DoTest (3, "Rand_array", TestRandMT);
            DoTest (4, "Matrx_algb", TestMatrixMath);
            DoTest (5, "Array_sort", TestSort);

            LcdConsole.WriteLine ("Press Enter for repeat tests");
            LcdConsole.WriteLine ("or Esc for exit...");
            WaitForEnterOrEscPress();
         }

      }

      static EventWaitHandle stopped = new ManualResetEvent(false);
      static bool bEscapeIsPressed = false;

      private static void WaitForEnterOrEscPress()
      {
         bEscapeIsPressed = false; 
         ButtonEvents buts = new ButtonEvents();
         buts.EnterPressed += () => stopped.Set();
         buts.EscapePressed += () => {bEscapeIsPressed = true; stopped.Set();};
         stopped.Reset ();
         stopped.WaitOne();
      }

      static Stopwatch sw = new Stopwatch ();

      private static void DoTest(int testNo, string testName, Action test)
      {
         sw.Reset ();
         sw.Start ();
         test();
         sw.Stop ();
         runtime[testNo] = sw.ElapsedMilliseconds;
         displayValue (testNo, sw.ElapsedMilliseconds, testName);
      }
   }

}


Code: Alles auswählen

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProjectGuid>{3A1C60BE-7FC2-491A-80A1-6B43F04B01F0}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>BrickBench</RootNamespace>
    <AssemblyName>BrickBench</AssemblyName>
    <UseMSBuildEngine>False</UseMSBuildEngine>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>
    <ConsolePause>false</ConsolePause>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <DebugType>full</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>
    <ConsolePause>false</ConsolePause>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="RandM.cs" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="MonoBrickFirmware">
      <HintPath>MonoBrickFirmware.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>


Code: Alles auswählen

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrickBench", "BrickBench\BrickBench.csproj", "{3A1C60BE-7FC2-491A-80A1-6B43F04B01F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3A1C60BE-7FC2-491A-80A1-6B43F04B01F0}.Debug|x86.ActiveCfg = Debug|x86
{3A1C60BE-7FC2-491A-80A1-6B43F04B01F0}.Debug|x86.Build.0 = Debug|x86
{3A1C60BE-7FC2-491A-80A1-6B43F04B01F0}.Release|x86.ActiveCfg = Release|x86
{3A1C60BE-7FC2-491A-80A1-6B43F04B01F0}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = BrickBench\BrickBench.csproj
EndGlobalSection
EndGlobal



Code: Alles auswählen

using System;

namespace BrickBench
{
   public static class RandM
   {
      static uint[] y = new uint[25];
      static int index = 25 + 1;
      const int M = 7;
      static readonly uint[] A = { 0, 0x8ebfd028 };

      public static uint Get()
      {
         if (index >= 25)
         {
            int k;
            if (index > 25)
            {
               uint 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;
         }

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

      public static int GetIntValue()
      {
         return unchecked((int)Get());
      }
   }
}



########################################################################################################

aktuelle Tabelle:
viewtopic.php?f=71&t=8095#p64772

References:
http://www.monobrick.dk/forums/topic/be ... #post-4523 ff.
Graphic Library by Vlad Ruzov: https://github.com/vladru/MonoBrickLcdExt
Memory Test by Vlad Ruzov: http://www.monobrick.dk/forums/topic/be ... #post-4623 ;
Sourcecode:
BrickMemory-master.zip
(47.09 KiB) 206-mal heruntergeladen


Zurück zu „Allgemeines zu Lego Mindstorms NXT und EV3“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 32 Gäste

Lego Mindstorms EV3, NXT und RCX Forum : Haftungsauschluss