'// 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 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()