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: 5402
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 10:30

2 Fragen hierzu:

Ist in C#/Mono
uint
eine 16-bit oder eine 32 bit Zahl ?
(in BCC/gpp C wäre 16-bit Integer int, und 32 bit Integer long)

wie sieht es in C#/Mono mit float (32 bit) und double (64 bit) aus?

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 » 9. Aug 2014 19:13

uint: 32-Bit

float: 32-Bit (7 Stellen)
double 64-Bit (15-16 Stellen)

Weil du sagst in gpp ist ein int 16b: in nxtOSEK ist ein int 32 bit und ein short 16 bit
Projekte und Informationen auf meiner Website: http://roboticsaumair.jimdo.com/

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5402
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 22:16

danke dir!
uint entspricht also "unsigned long",
und float und double entsprechen dann auch den BCC/gpp C Konventionen. Das war wichtig zu wissen.

Übrigens, wenn man "nur" int schreibt, ist in BCC/gpp C int=16bit, aber short kann man auch schreiben, das wäre dann das gleiche (CMIIW).

Wenn nun in C# int =32bit ist - gibt es dann dort ein long mit 64bit? Normalerweise wäre das logisch.

(Ich las mal, auf 8-16bit Prozessoren sei üblicherweise int=16bit, auf 32bit Prozessoren entsprechend int=32bit, long dann jeweils das doppelte, und short die Hälfte, aber nie kleiner 16bit; kA wo ich das her habe....)

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 » 11. Aug 2014 17:29

Wenn nun in C# int =32bit ist - gibt es dann dort ein long mit 64bit? Normalerweise wäre das logisch.


Korrekt.

(Ich las mal, auf 8-16bit Prozessoren sei üblicherweise int=16bit, auf 32bit Prozessoren entsprechend int=32bit, long dann jeweils das doppelte, und short die Hälfte, aber nie kleiner 16bit; kA wo ich das her habe....)


C/C++ Schreibt bei der Größe der Datentypen nicht viel vor außer.
char (1 byte) <= short (min 2 byte) <= int <= long (min 4 byte)
Nach dieser Regel kann also int nie kleiner als 16 bit sein stimmt. Üblicherweise ist es so wie du geschrieben hast. (würde mich aber bei c/c++ nie darauf verlassen, einfach mal ein sizeof(int) machen)
Projekte und Informationen auf meiner Website: http://roboticsaumair.jimdo.com/

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5402
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 » 11. Aug 2014 18:44

jep, das mit dem sizeof(int) stimmt!

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 » 22. Aug 2014 16:37

Update: Code für NXT nxtOSEK
Da sich in der API von NXtpandedLib was geändert hat, hier der aktuelle Code. Werte sind gleich geblieben.

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 schriftlicher Genehmigung durch den Autor.
// version 1.09.1

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



float test_float_math() {
   float s = M_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();
}

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

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5402
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 » 27. Aug 2014 20:25

dankeschön, ich werde den Code oben gleich aktualisieren!

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5402
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 » 5. Sep 2014 10:14

HaWe Brickbench Arduino IDE (Sketch/Wiring)
hier habe ich jetzt auch den Arduino Sketch C Code für den Arduino Mega 2560 und Arduino Due fertig,
inzwischen incl. Display-Benchmark-Tests (oweh, mit welchen Resultaten... ;) ).

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



Verwendete TFT Hardware: http://eckstein-shop.de/22-ILI9225-SPI- ... -C51-STM32

a) verwendete TFT Treiber von Nkawu: https://github.com/Nkawu/TFT_22_ILI9225

Code: Alles auswählen

// HaWe Brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// Autor: (C) Helmut Wunder 2013,2014
// ported to Arduino Sketch/Wiring by Helmut Wunder
// 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.0022-NkawuTFT22ILI9225


#include "SPI.h"
#include "TFT_22_ILI9225.h"

#define TFT_RST  8
#define TFT_RS   9  // D/C
#define TFT_CS  53  // SS
#define TFT_SDI 51  // MOSI
#define TFT_CLK 52  // SCK
#define TFT_LED  0  // 0 if wired to +5V directly

// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);


#define TimerMS() millis()

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, double *B, double *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];
         }
      }
   }
}


// matrix determinant

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

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


double test_matrix_math() {
  int x;

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

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;
    MatrixDet(2, A[0]);                          // <<<<<<<<<<<<<<<<<<<

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

    MatrixDet(3, S[0]);                          // <<<<<<<<<<<<<<<<<<<

  }

  s=(S[0][0]*S[1][1]*S[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;
}

inline void displayValues() {

  char buf[120];
  tft.clear();

    sprintf (buf, "%3d %9ld  int_Add",    0, runtime[0]); tft.drawText(0,10, buf);
    sprintf (buf, "%3d %9ld  int_Mult",   1, runtime[1]); tft.drawText(0,20, buf);
    sprintf (buf, "%3d %9ld  float_op",   2, runtime[2]); tft.drawText(0,30, buf);
    sprintf (buf, "%3d %9ld  randomize",  3, runtime[3]); tft.drawText(0,40, buf);
    sprintf (buf, "%3d %9ld  matrx_algb", 4, runtime[4]); tft.drawText(0,50, buf);
    sprintf (buf, "%3d %9ld  arr_sort",   5, runtime[5]); tft.drawText(0,60, buf);
    sprintf (buf, "%3d %9ld  TextOut",    6, runtime[6]); tft.drawText(0,70, buf);
    sprintf (buf, "%3d %9ld  Graphics",   7, runtime[7]); tft.drawText(0,80, buf);
   
   
}


int32_t test_TextOut(){
  int  y;
  char buf[120];
 
  for(y=0;y<20;++y) {   
    tft.clear();
    sprintf (buf, "%3d %9d  int_Add",    y, 1000);  tft.drawText(0,10, buf);
    sprintf (buf, "%3d %9d  int_Mult",   0, 1010);  tft.drawText(0,20, buf);
    sprintf (buf, "%3d %9d  float_op",   0, 1020);  tft.drawText(0,30, buf);
    sprintf (buf, "%3d %9d  randomize",  0, 1030);  tft.drawText(0,40, buf);
    sprintf (buf, "%3d %9d  matrx_algb", 0, 1040);  tft.drawText(0,50, buf);
    sprintf (buf, "%3d %9d  arr_sort",   0, 1050);  tft.drawText(0,60, buf);
    sprintf (buf, "%3d %9d  displ_txt",  0, 1060);  tft.drawText(0,70, buf);
    sprintf (buf, "%3d %9d  testing...", 0, 1070);  tft.drawText(0,80, buf);

  }
  return 66;
}


int32_t test_graphics(){
  int y;
  char buf[120];
 
  for(y=0;y<100;++y) {
    tft.clear();
    sprintf (buf, "%3d", y);  tft.drawText(0,80, buf); // outcomment for downwards compatibility

    tft.drawCircle(50, 40, 10, COLOR_WHITE);
    tft.fillCircle(30, 24, 10, COLOR_WHITE);
    tft.drawLine(10, 10, 60, 60, COLOR_WHITE);
    tft.drawLine(50, 20, 90, 70, COLOR_WHITE);
    tft.drawRectangle(20, 20, 40, 40, COLOR_WHITE);
    tft.fillRectangle(65, 25, 20, 30, COLOR_WHITE);
    //tft.drawEclipse(70, 30, 15, 20 , COLOR_WHITE); //  original test
    tft.drawCircle(70, 30, 15, COLOR_WHITE); // alternatively, just if no drawEclipse is avaiable in the Arduino graph libs!
  }
  }
  return 77;
}



int test(){

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

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


  // LcdClearDisplay();

  time0= TimerMS();;
  s=test_Int_Add();
  runtime[0]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  int_Add",    0, runtime[0]); Serial.println( buf);
  tft.drawText(0,10, buf);

  time0=TimerMS();
  s=test_Int_Mult();
  runtime[1]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  int_Mult",   1, runtime[1]); Serial.println( buf);
  tft.drawText(0,20, buf);

  time0=TimerMS();
  s=test_float_math();
  runtime[2]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  float_op",   2, runtime[2]); Serial.println( buf);
  tft.drawText(0,30, buf);

  time0=TimerMS();
  s=test_rand_MT();
  runtime[3]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  randomize",  3, runtime[3]); Serial.println( buf);
  tft.drawText(0,40, buf);

  time0=TimerMS();
  s=test_matrix_math();
  runtime[4]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  matrx_algb", 4, runtime[4]); Serial.println( buf);
  tft.drawText(0,50, buf);


  time0=TimerMS();
  s=test_Sort();
  runtime[5]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  arr_sort",   5, runtime[5]); Serial.println( buf);
  tft.drawText(0,60, buf);
 
  // lcd display text / graphs
 
  time0=TimerMS();
  s=test_TextOut();
  runtime[6]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  TextOut", 6, runtime[6]); Serial.println( buf);
  tft.drawText(0,70, buf);
 
  time0=TimerMS();
  s=test_graphics();
  runtime[7]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  Graphics", 7, runtime[7]); Serial.println( buf);
  tft.drawText(0,80, buf);
 

  Serial.println();
 
  y = 0;
  for (x = 0; x < 8; ++x) {
      y += runtime[x];
  }
 
  displayValues();
 
  sprintf (buf, "gesamt ms: %9ld ", y);
  Serial.println( buf);
  tft.drawText(0, 110, buf);
 
  x=50000000.0/y;
  sprintf (buf, "benchmark: %9ld ", x);
  Serial.println( buf);
  tft.drawText(0, 120, buf);

  return 1;

}



void setup() {
  tft.begin();
  Serial.begin(9600); 
 
  tft.setOrientation(1);
  tft.setFont(Terminal6x8);
  tft.clear();
}

void loop() {
  char  buf[120];
  test();
 
  sprintf (buf, "Ende HaWe brickbench");   
  Serial.println( buf);
  tft.drawText(0, 140, buf);
 
  while(1);
}



Code: Alles auswählen

Benchmark-Tests: http://www.mindstormsforum.de/viewtopic.php?f=71&t=8095#p64772
Mega:   
Text:     92016 ms
Graphic: 224137 ms   

Due:
Text:    35347 ms
Graphic: 138600 ms



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

b) Test mit UTFT- Grafik-Lib von Henning Karlsen:
QDTech-UTFT-Karlsen.zip
(5.58 MiB) 432-mal heruntergeladen



Code: Alles auswählen

// HaWe Brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// Autor: (C) Helmut Wunder 2013,2014
// ported to Arduino Sketch/Wiring by Helmut Wunder
// 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.0022-KarlsenUTFT

#include "SPI.h"
#include "UTFT.h"

// Declare which fonts we will be using
extern uint8_t SmallFont[];
//UTFT myGLCD(Model,SDA,SCL,CS,RST,RS)
//QD220A is for QDtech 2.2inch SPI LCD Module,Driver IC:ILI9225
UTFT myGLCD(QD220A,A2,A1,A5,A4,A3);   // Remember to change the model parameter to suit your display module!


#define TimerMS() millis()

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, double *B, double *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];
         }
      }
   }
}


// matrix determinant

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

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


double test_matrix_math() {
  int x;

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

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;
    MatrixDet(2, A[0]);                          // <<<<<<<<<<<<<<<<<<<

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

    MatrixDet(3, S[0]);                          // <<<<<<<<<<<<<<<<<<<

  }

  s=(S[0][0]*S[1][1]*S[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;
}

inline void displayValues() {

  char buf[120];
  myGLCD.clrScr();

    sprintf (buf, "%3d %9ld  int_Add",    0, runtime[0]); myGLCD.print(buf, 0,10);
    sprintf (buf, "%3d %9ld  int_Mult",   1, runtime[1]); myGLCD.print(buf, 0,20);
    sprintf (buf, "%3d %9ld  float_op",   2, runtime[2]); myGLCD.print(buf, 0,30);
    sprintf (buf, "%3d %9ld  randomize",  3, runtime[3]); myGLCD.print(buf, 0,40);
    sprintf (buf, "%3d %9ld  matrx_algb", 4, runtime[4]); myGLCD.print(buf, 0,50);
    sprintf (buf, "%3d %9ld  arr_sort",   5, runtime[5]); myGLCD.print(buf, 0,60);
    sprintf (buf, "%3d %9ld  TextOut",    6, runtime[6]); myGLCD.print(buf, 0,70);
    sprintf (buf, "%3d %9ld  Graphics",   7, runtime[7]); myGLCD.print(buf, 0,80);
   
   
}


int32_t test_TextOut(){
  int  y;
  char buf[120];
 
  for(y=0;y<20;++y) {   
    myGLCD.clrScr();
    sprintf (buf, "%3d %9d  int_Add",    y, 1000);  myGLCD.print(buf, 0,10);
    sprintf (buf, "%3d %9d  int_Mult",   0, 1010);  myGLCD.print(buf, 0,20);
    sprintf (buf, "%3d %9d  float_op",   0, 1020);  myGLCD.print(buf, 0,30);
    sprintf (buf, "%3d %9d  randomize",  0, 1030);  myGLCD.print(buf, 0,40);
    sprintf (buf, "%3d %9d  matrx_algb", 0, 1040);  myGLCD.print(buf, 0,50);
    sprintf (buf, "%3d %9d  arr_sort",   0, 1050);  myGLCD.print(buf, 0,60);
    sprintf (buf, "%3d %9d  displ_txt",  0, 1060);  myGLCD.print(buf, 0,70);
    sprintf (buf, "%3d %9d  testing...", 0, 1070);  myGLCD.print(buf, 0,80);

  }
  return 66;
}


int32_t test_graphics(){
  int y;
  char buf[120];
 
 
  for(y=0;y<100;++y) {
    myGLCD.clrScr();
    sprintf (buf, "%3d", y);  myGLCD.print(buf, 0,80); // outcomment for downwards compatibility

    myGLCD.drawCircle(50, 40, 10);
    myGLCD.fillCircle(30, 24, 10);
    myGLCD.drawLine(10, 10, 60, 60);
    myGLCD.drawLine(50, 20, 90, 70);
    myGLCD.drawRect(20, 20, 40, 40);
    myGLCD.fillRect(65, 25, 20, 30);
    //myGLCD.drawEclipse(70, 30, 15, 20); //  original test
    myGLCD.drawCircle(70, 30, 15); // alternatively, just if no drawEclipse is avaiable in the Arduino graph libs!

  }
  return 77;
}



int test(){

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

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


  // LcdClearDisplay();

  time0= TimerMS();;
  s=test_Int_Add();
  runtime[0]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  int_Add",    0, runtime[0]); Serial.println( buf);
  myGLCD.print(buf, 0,10);

  time0=TimerMS();
  s=test_Int_Mult();
  runtime[1]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  int_Mult",   1, runtime[1]); Serial.println( buf);
  myGLCD.print(buf, 0,20);

  time0=TimerMS();
  s=test_float_math();
  runtime[2]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  float_op",   2, runtime[2]); Serial.println( buf);
  myGLCD.print(buf, 0,30);

  time0=TimerMS();
  s=test_rand_MT();
  runtime[3]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  randomize",  3, runtime[3]); Serial.println( buf);
  myGLCD.print(buf, 0,40);

  time0=TimerMS();
  s=test_matrix_math();
  runtime[4]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  matrx_algb", 4, runtime[4]); Serial.println( buf);
  myGLCD.print(buf, 0,50);


  time0=TimerMS();
  s=test_Sort();
  runtime[5]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  arr_sort",   5, runtime[5]); Serial.println( buf);
  myGLCD.print(buf, 0,60);
 
  // lcd display text / graphs
 
  time0=TimerMS();
  s=test_TextOut();
  runtime[6]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  TextOut", 6, runtime[6]); Serial.println( buf);
  myGLCD.print(buf, 0,70);
 
  time0=TimerMS();
  s=test_graphics();
  runtime[7]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  Graphics", 7, runtime[7]); Serial.println( buf);
  myGLCD.print(buf, 0,80);
 

  Serial.println();
 
  y = 0;
  for (x = 0; x < 8; ++x) {
      y += runtime[x];
  }
 
  displayValues();
 
  sprintf (buf, "gesamt ms: %9ld ", y);
  Serial.println( buf);
  myGLCD.print(buf, 0,110);
 
  x=50000000.0/y;
  sprintf (buf, "benchmark: %9ld ", x);
  Serial.println( buf);
  myGLCD.print(buf, 0,120);

  return 1;

}



void setup() {
 
  Serial.begin(9600);
 
  // Setup the LCD
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  myGLCD.setColor(255, 255, 255);
}

void loop() {
  char  buf[120];
  test();
 
  sprintf (buf, "Ende HaWe brickbench");   
  Serial.println( buf);
  myGLCD.print(buf, 0, 140);
 
  while(1);
}


Code: Alles auswählen

Testergebnis mit Benchmark: http://www.mindstormsforum.de/viewtopic.php?f=71&t=8095#p64772
Mega:   
Text:     80618
Graphic: 224505

Due:
Text:    14808
Graphic: 40159



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


angepasst auf nodeMCU ESP8266 ESP-12F:

Code: Alles auswählen

// HaWe TFT Brickbench
// ported to Adafruit SSD1306 OLED library by HaWE



#include <Wire.h>

// For the Adafruit shield, these are the default.
#include <ESP_SSD1306.h>    // Modification of Adafruit_SSD1306 for ESP8266 compatibility
#include <Adafruit_GFX.h>   // Needs a little change in original Adafruit library (See README.txt file)

#define OLED_RESET    D0    // D0=GPIO16: OLED reset signal
ESP_SSD1306 display(OLED_RESET);


char textBuff[20];

#define  TimerMS() millis()

unsigned long runtime[8];


void TFTprint(char sbuf[], int16_t x, int16_t y) {
  display.setCursor(x, y);
  display.print(sbuf);
}
   



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, double *B, double *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];
         }
      }
   }
}


// matrix determinant

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

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


double test_matrix_math() {
  int x;

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

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;
    MatrixDet(2, A[0]);                          // <<<<<<<<<<<<<<<<<<<

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

    MatrixDet(3, S[0]);                          // <<<<<<<<<<<<<<<<<<<

  }

  s=(S[0][0]*S[1][1]*S[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;
}







inline void displayValues() {

  char buf[120];
  display.fillScreen(BLACK); // clrscr()

    sprintf (buf, "%3d %9ld  int_Add",    0, runtime[0]); TFTprint(buf, 0,10); display.display();
    sprintf (buf, "%3d %9ld  int_Mult",   1, runtime[1]); TFTprint(buf, 0,20); display.display();
    sprintf (buf, "%3d %9ld  float_op",   2, runtime[2]); TFTprint(buf, 0,30); display.display();
    sprintf (buf, "%3d %9ld  randomize",  3, runtime[3]); TFTprint(buf, 0,40); display.display();
    sprintf (buf, "%3d %9ld  matrx_algb", 4, runtime[4]); TFTprint(buf, 0,50); display.display();
    sprintf (buf, "%3d %9ld  arr_sort",   5, runtime[5]); TFTprint(buf, 0,60); display.display();
    sprintf (buf, "%3d %9ld  TextOut",    6, runtime[6]); TFTprint(buf, 0,70); display.display();
    sprintf (buf, "%3d %9ld  Graphics",   7, runtime[7]); TFTprint(buf, 0,80); display.display();
   
   
}


int32_t test_TextOut(){
  int  y;
  char buf[120];
 
  for(y=0;y<20;++y) {   
    display.clearDisplay();  // clrscr()
    sprintf (buf, "%3d %9d  int_Add",    y, 1000);  TFTprint(buf, 0, 8); display.display();
    sprintf (buf, "%3d %9d  int_Mult",   0, 1010);  TFTprint(buf, 0,16); display.display();
    sprintf (buf, "%3d %9d  float_op",   0, 1020);  TFTprint(buf, 0,24); display.display();
    sprintf (buf, "%3d %9d  randomize",  0, 1030);  TFTprint(buf, 0,32); display.display();
    sprintf (buf, "%3d %9d  matrx_algb", 0, 1040);  TFTprint(buf, 0,40); display.display();
    sprintf (buf, "%3d %9d  arr_sort",   0, 1050);  TFTprint(buf, 0,48); display.display();
    sprintf (buf, "%3d %9d  displ_txt",  0, 1060);  TFTprint(buf, 0,54); display.display();
    sprintf (buf, "%3d %9d  testing...", 0, 1070);  TFTprint(buf, 0,60); display.display();

  }
  return y;
}


int32_t test_graphics(){
  int y;
  char buf[120];
 
 
  for(y=0;y<100;++y) {
    display.clearDisplay();
    sprintf (buf, "%3d", y);  TFTprint(buf, 0,80); // outcomment for downwards compatibility

    display.drawCircle(50, 40, 10, WHITE); display.display();
    display.fillCircle(30, 24, 10, WHITE); display.display();
    display.drawLine(10, 10, 60, 60, WHITE); display.display();
    display.drawLine(50, 20, 90, 64, WHITE); display.display();
    display.drawRect(20, 20, 40, 40, WHITE); display.display();
    display.fillRect(65, 25, 20, 30, WHITE); display.display();
    //display.drawEllipse(70, 30, 15, 20); //  original test
    display.drawCircle(70, 30, 15, WHITE); // alternatively, just if no drawEclipse is avaiable in the Arduino graph libs!
    display.display();
  }
  return y;
}




int test(){

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

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


  // LcdClearDisplay();

  time0= TimerMS();;
  s=test_Int_Add();
  runtime[0]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  int_Add",    0, runtime[0]); Serial.println( buf);
  TFTprint(buf, 0,8);

  time0=TimerMS();
  s=test_Int_Mult();
  runtime[1]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  int_Mult",   1, runtime[1]); Serial.println( buf);
  TFTprint(buf, 0,16);

  time0=TimerMS();
  s=test_float_math();
  runtime[2]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  float_op",   2, runtime[2]); Serial.println( buf);
  TFTprint(buf, 0,24);

  time0=TimerMS();
  s=test_rand_MT();
  runtime[3]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  randomize",  3, runtime[3]); Serial.println( buf);
  TFTprint(buf, 0,32);

  time0=TimerMS();
  s=test_matrix_math();
  runtime[4]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  matrx_algb", 4, runtime[4]); Serial.println( buf);
  TFTprint(buf, 0,40);


  time0=TimerMS();
  s=test_Sort();
  runtime[5]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  arr_sort",   5, runtime[5]); Serial.println( buf);
  TFTprint(buf, 0,48);
 
  // lcd display text / graphs
 
  time0=TimerMS();
  s=test_TextOut();
  runtime[6]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  TextOut", 6, runtime[6]); Serial.println( buf);
  TFTprint(buf, 0,54);
 
  time0=TimerMS();
  s=test_graphics();
  runtime[7]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  Graphics", 7, runtime[7]); Serial.println( buf);
  TFTprint(buf, 0,60);
  display.display();

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


  delay(2000);
 
  display.clearDisplay();
  displayValues();
 
  sprintf (buf, "gesamt ms: %9ld ", y);
  Serial.println( buf);
  TFTprint(buf, 0, 10);
 
  x=50000000.0/y;
  sprintf (buf, "benchmark: %9ld ", x);
  Serial.println( buf);
  TFTprint(buf, 0, 20);
  display.display();

  return 1;

}




void setup() {
 
  Serial.begin(115200);
 
  // Setup the LCD
  // OLED + I2C
  Wire.begin(D4,D5);   //(I2C liegt beim nodeMCU auf pins D4=GPIO2=SDA  und D5=GPIO14=SCL, also anders als sonst
  delay(10);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)
  display.setRotation(0);

  display.setTextColor(WHITE);
  display.setFont();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.clearDisplay();
  display.setCursor( 0, 0);  display.print("OLED TEST OK");
  display.display();

  Serial.println("tft started");
  delay(3000);
  display.clearDisplay();
  display.display();
 
}

void loop() {
  char  buf[120];
  test();
 
  sprintf (buf, "Ende HaWe brickbench");   
  Serial.println( buf);
  TFTprint(buf, 0, 140);
 
  delay(3000);
}


Code: Alles auswählen

  0        11  int_Add
  1        43  int_Mult
  2       128  float_op
  3        15  randomize
  4        24  matrx_algb
  5       106  arr_sort




außer Konkurrenz, mit OLED SSD1306 (i2c):

Code: Alles auswählen

  6     18094  TextOut
  7     78709  Graphics
gesamt ms:     97130
benchmark:       514 


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

alle Arduino-Ergebnisse im Überblick:

Code: Alles auswählen

HaWe brickbench © test (time: ms)     Arduino         Arduino         Arduino     PJRC Teensy    ESP8266
Typ, OS, FW, PL, API                  Mega2560          Due             Zero          3.1        nodeMCU
MCU, cpu-Takt                        AVR/16MHz      ARM M3/84Mhz    ARM M0/48MHz  ARM M4/72MHz    80MHz
Firmware/vers.,Pr.Lang.            IDE 1.6x C++     IDE 1.6x C++    IDE 1.6x C++  IDE 1.6x C++   IDE 1.8.2
LCD / TFT (true color)             ILI9225 UTFT    ILI9341_due   (Adafr.ILI9340)  ILI9327 NC    ILI9340-SSD1306
screen size tested                    240*176         320*240         320*240       320*240     320*240/128/64
==============================================================================================================
 0 100000 integer add/subtr                129            8              15            5            11
 1 52000 integer multiply/division        1219            7             102            5            43 
 2 5000 transc. float operations           326          107             397           92           128
 3 Mersenne Tw. PRNG (&,^,>>,<<)           313            7              36            4            15   
 4 matrix algebra (prod/determ.)           244           23              92           19            24
 5 int array sort [500]                   1366          171             379          110           106
..............................................................................................................
interm.   time                            3415          323            1021          235           327
..............................................................................................................
 6 display text                          80618          973     (~DUE: 9200)        1667         9200-18094 
 7 display graphics                     224505         3255     (~DUE:41000)        3194        41000-78709   
==============================================================================================================
execution time                          308720         4551           51221         5096        50854-97130
speed bench score (50,000,000/ms)          162        10,997            976        9,812          983-  514

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

Re: HaWe brickbench Benchmark Test für NXT, EV3 & andere CPU

Beitragvon HaWe » 10. Nov 2014 21:10

update zu Mono C# Display Zeichen-Funktionen:
http://www.monobrick.dk/forums/topic/be ... #post-4964
I`m not sure that drawing functions are needed on the LegoBrick but I have done its for complete HW brickbench test.
Not so far Anders merged LcdDraw to the firmware and today Ifinally had the time for finish the test.
I hope that Helmut will looking into this message and will update results table on his site.

The full test source can be found here: https://github.com/vladru/MonoBrickBench

The application can be builded in Xamarin studio 5.5.3 with MonoBrick firmware Add-In.
If you will try to open this project in Visual Studio you will catch unsupported format error. Probably this issue caused by using of Xamarin Add-In.
Below the timing (in milliseconds) of steps that was missing in the previous C# test release:
Display_text test (5 loops): 395, 242, 268, 259, 262
Graphics test (5 loops): 475, 180, 182, 172, 199


aktuellste Benchmark-Übersicht wie immer hier: viewtopic.php?f=71&t=8095&start=60#p64772
Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E

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

Re: HaWe brickbench Benchmark Test f. NXT, EV3 & andere

Beitragvon HaWe » 13. Feb 2015 15:56

bitte bei allen Tests beachten:
wegen eines nan-Bugs wurde der float_math Test abgeändert :

Code: Alles auswählen

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


es ändern sich die Teil-Benchmark-Laufzeiten hier teilweise nach unten, teilweise nach oben.

Benchmark-Werte wurden inzwischen korrigiert und aktualisiert für:
NXT/NXC, EV3/BCC-C, EV3/Lejos, EV3/C#Mono, EV3-Basic, Arduino Mega, Arduino Due

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

Benutzeravatar
c0pperdragon
Schreibt viel
Schreibt viel
Beiträge: 231
Registriert: 9. Feb 2015 00:29

Re: HaWe brickbench Benchmark Test f. NXT, EV3 & andere

Beitragvon c0pperdragon » 24. Feb 2015 15:03

Code für ev3-Basic
Im vorigen Post muss mit der Zeilenformatierung irgendwas schiefgegangen sein. Ich poste das jetzt nochmal.

Code: Alles auswählen

'// HaWe Brickbench
'// benchmark test for NXT/EV3 and similar Micro Controllers
'// 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/
'// ported to EV3-Basic: Reinhard Grafl
'// version 1.09.0

'PRAGMA NOBOUNDSCHECK
'PRAGMA NODIVISIONCHECK


runtime=Vector.Init(8,-1)
A = Vector.Init(500,0)
B = Vector.Init(500,0)
C = Vector.Init(500,0)

PI = Math.PI


'--------------------------------------------
' Matrix Algebra
'--------------------------------------------

' matrix determinant
MD_A = Vector.Init(0,0)
MD_RESULT = 0
Sub MatrixDet1x1
  MD_RESULT = MD_A[0] 
EndSub
Sub MatrixDet2x2
  MD_RESULT = MD_A[0*2+0]*MD_A[1*2+1]- MD_A[0*2+1]*MD_A[1*2+0]
EndSub
Sub MatrixDet3x3
  MD_RESULT =             MD_A[0*3+0]*MD_A[1*3+1]*MD_A[2*3+2]
  MD_RESULT = MD_RESULT + MD_A[0*3+1]*MD_A[1*3+2]*MD_A[2*3+0]
  MD_RESULT = MD_RESULT + MD_A[0*3+2]*MD_A[1*3+0]*MD_A[2*3+1]
  MD_RESULT = MD_RESULT - MD_A[0*3+2]*MD_A[1*3+1]*MD_A[2*3+0]
  MD_RESULT = MD_RESULT - MD_A[0*3+1]*MD_A[1*3+0]*MD_A[2*3+2]
  MD_RESULT = MD_RESULT - MD_A[0*3+0]*MD_A[1*3+2]*MD_A[2*3+1]
EndSub


' --------------------------------------------
'  benchmark test procedures
' --------------------------------------------

SUB test_Int_Add
  i=1
  j=11
  k=112
  l=1111
  m=11111
  n=-1
  o=-11
  p=-111
  q=-1112
  r=-11111
  s=0
  For x=0 to 9999
    s=s+i
    s=s+j
    s=s+k
    s=s+l
    s=s+m
    s=s+n
    s=s+o
    s=s+p
    s=s+q
    s=s+r
  endfor
ENDSUB


SUB test_Int_Mult
  for y=0 To 1999
    s=1
    for x=1 to 13
      s = s*x
    endfor
    for x=13 to 1 step -1
       s = s/x
    endfor
  endfor
ENDSUB


SUB test_float_math
  s=Math.PI
  for y=1 To 1000
     s=s*Math.SquareRoot(s)
     s=Math.Sin(s)
     s=Math.Power(2.71828182846,s)
     s=s*s
  endfor
ENDSUB



'long test_rand_MT(){
'  volatile unsigned long s;
'  int y;
'
'  for(y=0;y<5000;++y) {
'     s=randM()%10001;
'  }
'  return s;
'}

 
Sub test_matrix_math
  LA = Vector.Init(2*2,0) 
  LB = Vector.Init(2*2,0)
  LO = Vector.Init(3*3,0)

  for x=1 To 250     
    LA[0*2+0]=1
    LA[0*2+1]=3
    LA[1*2+0]=2
    LA[1*2+1]=4

    LB[0*2+0]=10
    LB[0*2+1]=30
    LB[1*2+0]=20
    LB[1*2+1]=40
 
    LC = Vector.Multiply(2,2,2,LA,LB)

    LA[0*2+0]=1
    LA[0*2+1]=3
    LA[1*2+0]=2
    LA[1*2+1]=4
 
    MD_A = LA 
    MatrixDet2x2()

    LO[0*3+0]=1
    LO[0*3+1]=4
    LO[0*3+2]=7
    LO[1*3+0]=2
    LO[1*3+1]=5
    LO[1*3+2]=8
    LO[2*3+0]=3
    LO[2*3+1]=6
    LO[2*3+2]=9   
   
    MD_A = LO
    MatrixDet3x3()
  endfor

  s=LO[0*3+0]*LO[1*3+1]*LO[2*3+2]
endsub


SUB test_Sort
  for Y=1 To 30
    T = Vector.Sort(500,A)   
    T = Vector.Sort(500,B)
    T = Vector.Sort(500,C)
 EndFor
endsub

SUB test_TextOut
  for y=0 to 19
    LCD.StopUpdate()
    LCD.Clear()
    LCD.Text(1, 0,10, 1, 0+" "+1000+" int_Add")
    LCD.Text(1, 0,20, 1, 1+" "+1000+" int_Mult")
    LCD.Text(1, 0,30, 1, 2+" "+1000+" float_op")
    LCD.Text(1, 0,40, 1, 3+" "+1000+" randomize")
    LCD.Text(1, 0,50, 1, 4+" "+1000+" matrx_algb")
    LCD.Text(1, 0,60, 1, 5+" "+1000+" arr_sort")
    LCD.Text(1, 0,70, 1, 6+" "+1000+" displa_txt")
    LCD.Text(1, 0,80, 1, 7+" "+1000+" testing...")
    LCD.Update()
  endfor
EndSub

SUB test_graphics
  for y=0 To 99
    LCD.StopUpdate()
    LCD.Clear()
    LCD.Circle(1, 50, 40, 10)
    LCD.FillCircle(1, 30, 24, 10)
    LCD.Line(1, 10, 10, 60, 60)
    LCD.Line(1, 50, 20, 90, 70)
    LCD.Rect(1, 20, 20, 40, 40)
    LCD.FillRect(1, 65, 25, 20, 30)
    LCD.Circle(1, 70, 30, 15)
    LCD.Update()
  endfor
endsub

Sub displayValues
  LCD.Clear()
  LCD.Text(1, 0,10, 1, "0: " + runtime[0] + " int_Add")
  LCD.Text(1, 0,20, 1, "1: " + runtime[1] + " int_Mult")
  LCD.Text(1, 0,30, 1, "2: " + runtime[2] + " float_op")
  LCD.Text(1, 0,40, 1, "3: " + runtime[3] + " randomize")
  LCD.Text(1, 0,50, 1, "4: " + runtime[4] + " matrix_algb")
  LCD.Text(1, 0,60, 1, "5: " + runtime[5] + " arr_sort")
  LCD.Text(1, 0,70, 1, "6: " + runtime[6] + " displ_txt")
  LCD.Text(1, 0,80, 1, "7: " + runtime[7] + " graphics")
endsub


'--- MAIN PROGRAM ----

  LCD.Clear()
  LCD.Text(1, 0,10, 1,"hw brickbench")
  LCD.Text(1, 0,20, 1,"(C)H.Wunder 2013")
  LCD.Text(1, 0,30, 1,"EV3-Basic port: c0pperdragon")
  LCD.Text(1, 0,50, 1,"initializing...")

  for y=0 To 499
    A[y]=Math.GetRandomNumber(30000)-1
    B[y]=Math.GetRandomNumber(30000)-1
    C[y]=Math.GetRandomNumber(30000)-1
  endfor
   
  LCD.Clear()
 
  time0=EV3.Time
  test_Int_Add()
  runtime[0]=EV3.Time - time0
  displayValues()

  time0=EV3.Time
  test_Int_Mult()
  runtime[1]=EV3.Time -time0
  displayValues()

  time0=EV3.Time
  test_float_math()
  runtime[2]=EV3.Time -time0
  displayValues()

  time0=EV3.Time
'  test_rand_MT();
  runtime[3]=EV3.Time-time0
  displayValues()

  time0=EV3.Time
  test_matrix_math()
  runtime[4]=EV3.Time-time0
  displayValues()

  time0=EV3.Time
  test_Sort()
  runtime[5]=EV3.Time-time0
  displayValues()

  time0=EV3.Time
  test_TextOut()
  runtime[6]=EV3.Time-time0
  displayValues()

  time0=EV3.Time
  test_graphics()
  runtime[7]=EV3.Time-time0
  displayValues()
 
  y=0
  For x=0 To 7
    y = y + runtime[x]
  endfor 
  LCD.Text(1, 0,95, 1, "total ms: " + y)
  LCD.Text(1, 0,105, 1, "benchmark: " + (50000000/y )) 
 
  Buttons.Flush()
  Buttons.Wait()


Ergebnisse :

Code: Alles auswählen

int-add 611
int-mult 909
float 148
mersenne -
matrix 409
sort 18660
text 219
graphics 278

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

Re: HaWe brickbench Benchmark Test f. NXT, EV3 & andere

Beitragvon HaWe » 18. Sep 2015 14:51

neue Grafik-Lib ILI9341_due getestet! Link: https://github.com/marekburiak/ILI9341_due

geeignet u.a. für Arduino DUE und ebenfalls UNO und MEGA etc.
Vorteil: volle Ausnutzung des Hardware-SPI-Busses mit schneller Taktung!

Testergebnis mit DUE: Text 15x so schnell wie UTFT, Grafics 13x so schnell wie UTFT !

Code: Alles auswählen

Benchmark für Due:
ILI9341_due tft
TextOut          973 
Graphics        3255 
gesamt ms:      4228



Code: Alles auswählen

// HaWe TFT Brickbench
// ported to ILI9341_due library by HaWE


#include <SPI.h>

// ILI9341_due NEW lib by Marek Buriak http://marekburiak.github.io/ILI9341_due/
#include "ILI9341_due_config.h"
#include "ILI9341_due.h"
#include "SystemFont5x7.h"
//#include "Streaming.h"

// For the Adafruit shield, these are the default.
/*
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
*/

#define    tft_cs     50
#define    tft_dc     49
#define    tft_rst     0


ILI9341_due tft = ILI9341_due(tft_cs, tft_dc, tft_rst);

char textBuff[20];

// Color set
#define   BLACK           0x0000
#define   RED             0xF800
#define   GREEN           0x07E0
//#define   BLUE            0x001F
#define   BLUE            0x102E
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define ORANGE          0xFD20
#define GREENYELLOW     0xAFE5
#define DARKGREEN       0x03E0
#define WHITE           0xFFFF

uint16_t  color;
uint16_t  colorFONDO = BLACK;


#define  TimerMS() millis()

unsigned long runtime[8];


void TFTprint(char sbuf[], int16_t x, int16_t y) {
  tft.cursorToXY(x, y);
  tft.print(sbuf);
}
   

inline void displayValues() {

  char buf[120];
  tft.fillScreen(BLACK); // clrscr()

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


int32_t test_TextOut(){
  int  y;
  char buf[120];
 
  for(y=0;y<20;++y) {   
    tft.fillScreen(BLACK); // clrscr()
    sprintf (buf, "%3d %9d  int_Add",    y, 1000);  TFTprint(buf, 0,10);
    sprintf (buf, "%3d %9d  int_Mult",   0, 1010);  TFTprint(buf, 0,20);
    sprintf (buf, "%3d %9d  float_op",   0, 1020);  TFTprint(buf, 0,30);
    sprintf (buf, "%3d %9d  randomize",  0, 1030);  TFTprint(buf, 0,40);
    sprintf (buf, "%3d %9d  matrx_algb", 0, 1040);  TFTprint(buf, 0,50);
    sprintf (buf, "%3d %9d  arr_sort",   0, 1050);  TFTprint(buf, 0,60);
    sprintf (buf, "%3d %9d  displ_txt",  0, 1060);  TFTprint(buf, 0,70);
    sprintf (buf, "%3d %9d  testing...", 0, 1070);  TFTprint(buf, 0,80);

  }
  return y;
}


int32_t test_graphics(){
  int y;
  char buf[120];
 
 
  for(y=0;y<100;++y) {
    tft.fillScreen(BLACK);
    sprintf (buf, "%3d", y);  TFTprint(buf, 0,80); // outcomment for downwards compatibility

    tft.drawCircle(50, 40, 10, WHITE);
    tft.fillCircle(30, 24, 10, WHITE);
    tft.drawLine(10, 10, 60, 60, WHITE);
    tft.drawLine(50, 20, 90, 70, WHITE);
    tft.drawRect(20, 20, 40, 40, WHITE);
    tft.fillRect(65, 25, 20, 30, WHITE);
    //tft.drawEllipse(70, 30, 15, 20); //  original test
    tft.drawCircle(70, 30, 15, WHITE); // alternatively, just if no drawEclipse is avaiable in the Arduino graph libs!

  }
  return y;
}



int test(){

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

 
 
  // lcd display text / graphs
 
  time0=TimerMS();
  s=test_TextOut();
  runtime[6]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  TextOut", 6, runtime[6]); Serial.println( buf);
  TFTprint(buf, 0,70);
 
  time0=TimerMS();
  s=test_graphics();
  runtime[7]=TimerMS()-time0;
  sprintf (buf, "%3d %9ld  Graphics", 7, runtime[7]); Serial.println( buf);
  TFTprint(buf, 0,80);
 

  Serial.println();
 
  y = 0;
  for (x = 0; x < 8; ++x) {
      y += runtime[x];
  }
 
  displayValues();
 
  sprintf (buf, "gesamt ms: %9ld ", y);
  Serial.println( buf);
  TFTprint(buf, 0,110);
 
  x=50000000.0/y;
  sprintf (buf, "benchmark: %9ld ", x);
  Serial.println( buf);
  TFTprint(buf, 0,120);

  return 1;

}



void setup() {
 
  Serial.begin(115200);
 
  // Setup the LCD

  tft.begin();
  tft.setRotation(iliRotation270);
  tft.fillScreen(colorFONDO);
  tft.setFont(SystemFont5x7); 

  tft.setTextColor(WHITE);

  Serial.println("tft started");
 
}

void loop() {
  char  buf[120];
  test();
 
  sprintf (buf, "Ende HaWe brickbench");   
  Serial.println( buf);
  TFTprint(buf, 0, 140);
 
  while(1);
}


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

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

Re: HaWe brickbench Benchmark Test f. NXT, EV3 & andere

Beitragvon HaWe » 16. Okt 2015 15:25

Brickbench Test für Raspberry Pi (gpp C++)

(getestet mit Raspberry Pi B+, Raspberry Pi 2 Model B, und Raspberry Pi 3 ! )

Geany settings for make/build:
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -o "%e" "%f" -lshapes -L/opt/vc/lib -lOpenVG -lEGL -pthread -lrt -lwiringPi

Die Benchmark-Ergebnisse schwanken etwas je nach Aktivität von Linux Kernel und gleichzeitig laufenden Hintergrundtasks bzw. Daemons.
Der Pi2 läuft außerdem nicht konstant bei 900 MHz sondern variabel je nach cpu-Last zwischen 600-900 Hz
( s.: https://www.raspberrypi.org/forums/view ... 97#p711501 )

Code: Alles auswählen

// HaWe Brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: GCC, Raspi, Raspbian  Linux
// Autor: (C) Helmut Wunder 2013,2014
// ported to Raspi  by "HaWe"
//
// 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.007  25.10.2015


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


#include <stdint.h>
#include <time.h>
#include <sys/time.h>

//#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"


unsigned long runtime[8];

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

uint32_t timer()
{
   struct timeval now;
   uint32_t ticks;
   gettimeofday(&now, NULL);
   ticks=now.tv_sec*1000+now.tv_usec/1000;
   return(ticks);
}


//--------------------------------------------
// 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, double *B, double *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];
         }
      }
   }
}


// matrix determinant

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

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



double test_matrix_math() {
  int x;

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

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;
    MatrixDet(2, A[0]);                          // <<<<<<<<<<<<<<<<<<<

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

    MatrixDet(3, S[0]);                          // <<<<<<<<<<<<<<<<<<<

  }

  s=(S[0][0]*S[1][1]*S[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;
  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=77;
  char buf[120];

  for(y=0;y<20;++y) {
   
    Background(0, 0, 0);                    // Black background
   
    //Text(x, y, buf, SerifTypeface, 10);
    Fill(255, 255, 255, 1);                 // White text
   
    sprintf (buf, "%3d %4d  int_Add",    0, 1000); Text( 20, 200- 20, buf, SerifTypeface, 10); End();
    sprintf (buf, "%3d %4d  int_Mult",   1, 1010); Text( 20, 200- 40, buf, SerifTypeface, 10); End();
    sprintf (buf, "%3d %4d  float_op",   2, 1020); Text( 20, 200- 60, buf, SerifTypeface, 10); End();
    sprintf (buf, "%3d %4d  randomize",  3, 1030); Text( 20, 200- 80, buf, SerifTypeface, 10); End();
    sprintf (buf, "%3d %4d  matrx_algb", 4, 1040); Text( 20, 200-100, buf, SerifTypeface, 10); End();
    sprintf (buf, "%3d %4d  arr_sort",   5, 1050); Text( 20, 200-120, buf, SerifTypeface, 10); End();
    sprintf (buf, "%3d %4d  displ_txt",  6, 1060); Text( 20, 200-140, buf, SerifTypeface, 10); End();
    sprintf (buf, "%3d %4d  testing...", 7, 1070); Text( 20, 200-160, buf, SerifTypeface, 10); End();

  }

  return y;
}



long test_graphics(){
    int y=0;
     
    for(y=0;y<100;++y) {
        WindowClear();      // Colour and size are remembered from the
                            // ClearWindowRGBA() call at the start of the program
        Stroke(255, 255, 255, 1);  // Set these at the start, no need to
        Fill(255,255,255, 1);      // keep calling them if colour hasn't changed
        StrokeWidth(1.0);
       
        End();
   
        CircleOutline(50, 40, 10);       // circles
        End();

        Circle(30, 24, 10);
        End();

        Line(10, 10, 60, 60);            // just 2 intersecting lines
        End();
        Line(50, 20, 90, 70);
        End();

        RectOutline(20, 20, 40, 40);     // rectangles
        End();
     
        Rect(65, 25, 20, 30);
        End();

        EllipseOutline(70, 30, 15, 20);  // ellipse
        End();
    }
    return y;
}




inline void displayValues() {

  char buf[120];
   
    WindowClear();      // Colour and size are remembered the start of the program

    sprintf (buf, "%3d %7ld  int_Add",    0, runtime[0]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  int_Mult",   1, runtime[1]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  float_op",   2, runtime[2]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  randomize",  3, runtime[3]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  matrx_algb", 4, runtime[4]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  arr_sort",   5, runtime[5]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  displ_txt",  6, runtime[6]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  graphics",   7, runtime[7]); printf(buf); printf("\n");
}



int main(){

  unsigned long time0, x, y;
  float s;
  char  buf[120];
  int width, height;
  char str[3];

  init(&width, &height);                  // Graphics initialization
  Start(width, height);                   // Start the picture
   
  WindowClear();
  WindowOpacity(255);       // Hide  the picture   

  printf("hw brickbench"); printf("\n");
  printf("initializing..."); printf("\n");
 

  for(y=0;y<500;++y) {
    a[y]=randM()%30000; b[y]=randM()%30000; c[y]=randM()%30000;
  }
 
  time0= timer();
  s=test_Int_Add();
  runtime[0]=timer()-time0;
  sprintf (buf, "%3d %7ld  int_Add",    0, runtime[0]);  printf(buf); printf("\n");

  time0=timer();
  s=test_Int_Mult();
  runtime[1]=timer()-time0;
  sprintf (buf, "%3d %7ld  int_Mult",   0, runtime[1]);  printf(buf); printf("\n");

  time0=timer();
  s=test_float_math();
  runtime[2]=timer()-time0;
  sprintf (buf, "%3d %7ld  float_op",   0, runtime[2]);  printf(buf); printf("\n");

  time0=timer();
  s=test_rand_MT();
  runtime[3]=timer()-time0;
  sprintf (buf, "%3d %7ld  randomize",  0, runtime[3]);  printf(buf); printf("\n");

  time0=timer();
  s=test_matrix_math();
  runtime[4]=timer()-time0;
  sprintf (buf, "%3d %7ld  matrx_algb", 0, runtime[4]);  printf(buf); printf("\n");


  time0=timer();
  s=test_Sort();
  runtime[5]=timer()-time0;
  sprintf (buf, "%3d %7ld  arr_sort",   0, runtime[5]);  printf(buf); printf("\n");
 
  time0=timer();
  s=test_TextOut();
  runtime[6]=timer()-time0;

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

  WindowOpacity(0);       // Hide  the picture   

  y=0;
  for(x=0;x<8;++x) {y+= runtime[x];}
  printf("\n");
  printf("\n");
 

   
  displayValues();

  sprintf (buf, "gesamt ms: %ld ", y);           printf(buf); printf("\n");
  sprintf (buf, "benchmark: %ld ", 50000000/y ); printf(buf); printf("\n");



  fgets(str, 2, stdin);                   // look at the pic, end with [RETURN]
  finish();                               // Graphics cleanup
  exit(0);
}



Variante für OLED I2C SH1106 (@400kHz) 128x64:

Code: Alles auswählen

// HaWe Brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: GCC, Raspi, Raspbian  Linux
// Autor: (C) Helmut Wunder 2013,2014
// ported to Raspi  by "HaWe"
//
// 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.OLED.007  16.08.2015
// OLED 128x64  i2c-1 clock = 400000

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


#include <stdint.h>
#include <time.h>
#include <sys/time.h>


#include <ArduiPi_OLED_lib.h>
#include <Adafruit_GFX.h>
#include <ArduiPi_OLED.h>
#include <getopt.h>


// Instantiate the display
ArduiPi_OLED display;



unsigned long runtime[8];

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

uint32_t timer()
{
   struct timeval now;
   uint32_t ticks;
   gettimeofday(&now, NULL);
   ticks=now.tv_sec*1000+now.tv_usec/1000;
   return(ticks);
}


//--------------------------------------------
// 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, double *B, double *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];
         }
      }
   }
}


// matrix determinant

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

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







double test_matrix_math() {
  int x;

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

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;
    MatrixDet(2, A[0]);                          // <<<<<<<<<<<<<<<<<<<

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

    MatrixDet(3, S[0]);                          // <<<<<<<<<<<<<<<<<<<

  }

  s=(S[0][0]*S[1][1]*S[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;
  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=77;
  char buf[120];
  display.setTextSize(1);
  display.setTextColor(WHITE);

  for(y=0;y<20;++y) {
    display.clearDisplay();
   
    sprintf (buf, "%3d %4d  int_Add",    0, 1000); display.setCursor(6, 0);  display.printf(buf); display.display();
    sprintf (buf, "%3d %4d  int_Mult",   1, 1010); display.setCursor(6, 8);  display.printf(buf); display.display();
    sprintf (buf, "%3d %4d  float_op",   2, 1020); display.setCursor(6,16);  display.printf(buf); display.display();
    sprintf (buf, "%3d %4d  randomize",  3, 1030); display.setCursor(6,24);  display.printf(buf); display.display();
    sprintf (buf, "%3d %4d  matrx_algb", 4, 1040); display.setCursor(6,32);  display.printf(buf); display.display();
    sprintf (buf, "%3d %4d  arr_sort",   5, 1050); display.setCursor(6,40);  display.printf(buf); display.display();
    sprintf (buf, "%3d %4d  displ_txt",  6, 1060); display.setCursor(6,48);  display.printf(buf); display.display();
    sprintf (buf, "%3d %4d  testing...", 7, 1070); display.setCursor(6,56);  display.printf(buf); display.display();
   

  }

  return y;
}



long test_graphics(){
    int y=0;
     
    for(y=0;y<100;++y) {
       
        display.clearDisplay();
   
        display.drawCircle(50, 40, 10, WHITE);  // circles
        display.display();

        display.fillCircle(30, 24, 10, WHITE);
        display.display();

        display.drawLine(10, 10, 60, 60, WHITE);   // just 2 intersecting lines
        display.display();
        display.drawLine(50, 20, 97, 63, WHITE);
        display.display();

        display.drawRect(20, 20, 40, 40, WHITE);     // rectangles
        display.display();
     
        display.fillRect(65, 25, 20, 30, WHITE);
        display.display();

        display.drawCircle(70, 30, 20, WHITE);  // no ellipse
        display.display();
    }
    return y;
}




inline void displayValues() {

  char buf[120];
   
    sprintf (buf, "%3d %7ld  int_Add",    0, runtime[0]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  int_Mult",   1, runtime[1]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  float_op",   2, runtime[2]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  randomize",  3, runtime[3]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  matrx_algb", 4, runtime[4]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  arr_sort",   5, runtime[5]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  displ_txt",  6, runtime[6]); printf(buf); printf("\n");
    sprintf (buf, "%3d %7ld  graphics",   7, runtime[7]); printf(buf); printf("\n");
}



int main(){

  unsigned long time0, x, y;
  float s;
  char  buf[120];
 
  char str[3];
 
  int i;
   
  // Oled supported display in ArduiPi_SSD1306.h

  // I2C change parameters to fit to your LCD
  if ( !display.init(OLED_I2C_RESET, 6) )
      exit(EXIT_FAILURE);

  display.begin();

  printf("hw brickbench"); printf("\n");
  printf("initializing..."); printf("\n");
 

  for(y=0;y<500;++y) {
    a[y]=randM()%30000; b[y]=randM()%30000; c[y]=randM()%30000;
  }
 
  time0= timer();
  s=test_Int_Add();
  runtime[0]=timer()-time0;
  sprintf (buf, "%3d %7ld  int_Add",    0, runtime[0]);  printf(buf); printf("\n");

  time0=timer();
  s=test_Int_Mult();
  runtime[1]=timer()-time0;
  sprintf (buf, "%3d %7ld  int_Mult",   0, runtime[1]);  printf(buf); printf("\n");

  time0=timer();
  s=test_float_math();
  runtime[2]=timer()-time0;
  sprintf (buf, "%3d %7ld  float_op",   0, runtime[2]);  printf(buf); printf("\n");

  time0=timer();
  s=test_rand_MT();
  runtime[3]=timer()-time0;
  sprintf (buf, "%3d %7ld  randomize",  0, runtime[3]);  printf(buf); printf("\n");

  time0=timer();
  s=test_matrix_math();
  runtime[4]=timer()-time0;
  sprintf (buf, "%3d %7ld  matrx_algb", 0, runtime[4]);  printf(buf); printf("\n");


  time0=timer();
  s=test_Sort();
  runtime[5]=timer()-time0;
  sprintf (buf, "%3d %7ld  arr_sort",   0, runtime[5]);  printf(buf); printf("\n");
 
  time0=timer();
  s=test_TextOut();
  runtime[6]=timer()-time0;

  time0=timer();
  s=test_graphics();
  runtime[7]=timer()-time0;
 
  y=0;
  for(x=0;x<8;++x) {y+= runtime[x];}
  printf("\n");
  printf("\n");
   
  displayValues();

  sprintf (buf, "gesamt ms: %ld ", y);           printf(buf); printf("\n");
  sprintf (buf, "benchmark: %ld ", 50000000/y ); printf(buf); printf("\n");

  fgets(str, 2, stdin);                   // look at the pic, end with [RETURN]
 
  exit(0);
}



Code: Alles auswählen

Ergebnis für Raspberry Pi B+ bei 800 MHz (leicht übertaktet
(in Einzelfällen bei den letzten 3 Tests (sort, text, graph)  um wenige ms schwankend):



bench test   ms B+    2B
cpu clock   800MHz 900MHz
Grafik:        openvg       OLED
Screen:     HDMI 1060x600  128x64
int_add         1      1       1
int_mult        3      4       3
float_op       13      2       1
mersenne        2      1       1   
matrix          1      2       1
arr_sort       88     46      30
text         2630   2626    6036
graph       13333  13333   27289

gesamt ms:  16072  16015   33362
Benchmark:   3111   3122    1498




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

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

Re: HaWe brickbench Benchmark Test f. NXT, EV3 & andere

Beitragvon HaWe » 5. Mär 2016 17:49

erste Ergebnisse auch für Raspberry Pi 3 im Verglich zum 2B, gemacht von einem anderen Tester aus dem Roboternetz-Forum:

Code: Alles auswählen

Raspi2
0   1 int_Add
1   3 int_Mult
2   2 float_op
3   1 randomize
4   1 matrx_algb
5   46 arr_sort


Code: Alles auswählen

Raspi3
0   1 int_Add
1   3 int_Mult
2   2 float_op
3   1 randomize
4   1 matrx_algb
5   42 arr_sort


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

Raspberry Pi C/C++ Referenz Code:
viewtopic.php?f=71&t=8095&start=15#p67795


hier sieht man, dass der Raspi 3 derzeit mit dem 32bit Jessie nicht bzw. kaum erkennbar schneller ist als der Raspi 2. Man muss allerdings - eigentlich - die Testdauer inzwischen verlängern und auch Bruchteile von Millisekunden auswerten, denn die neuen raspis sind einfachzu schnell für den Test im Vergleich zu NXC und RobotC etc. auf NXT und EV3. Ich werde dafür jetzt floats zum Zeitstoppen einführen.
Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E

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

Re: HaWe brickbench Benchmark Test f. NXT, EV3 & andere

Beitragvon HaWe » 14. Apr 2017 11:17

gibt es jemanden, der in der Lage ist, den Brickbench Benchmark-Code
viewtopic.php?f=71&t=8095#p64494
viewtopic.php?f=71&t=8095&start=15#p67795
auf Python zu portieren?
Ich wäre sehr gespannt, wie schnell Python bei Rechenoperationen arbeitet im Vergleich zu den anderen Programmiersprachen.

Bei reinen IO-Zugriffen (lesen und schreiben von Sensorpins) hat es sich bereits herausgestellt, dass auf einem Raspi C/C++ etwa 100x bis max. sogar 1000x schneller ist als Python - auf einem EV3 wird das sicher ähnlich sein.

Was mich hier aber interessiert, ist die Rechenperformance für low-level und high-level-Berechnungen, wie sie im Brickbench zu Testzwecken verwendet werden.
Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E


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

Wer ist online?

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

Lego Mindstorms EV3, NXT und RCX Forum : Haftungsauschluss