About half a year ago I made a benchmark for the arduino because I wanted to see how much faster my then new arduino due was than my arduino uno and micro. I don't know why, but I decided that I will(perhaps, not sure yet) start programming arduino again(since that benchmark I pretty much didn't even touch arduino anymore). The main reason that I stopped arduino was cause I suck at hardware stuff so I couldn't really do anything special, but I did make pong(and I tried to make don't touch the spikes(an amazing remake of flappy bird), but resistive touchscreens are not really meant for capacitive uses), if anyone is interested.
Anyways, back to the arduinos and my benchmark. My benchmark has a large macro, which is divided by the time the arduino took to complete the benchmark. That time is the score the arduino gets at the end. The due turned out to indeed be a lot faster and got a score almost six times as big as the uno and micro, and, unsurprisingly, and my micro got a slightly lower(but practically insignificant) score compared to my uno. Here is my code:
#define ITER 200000L
#define SCORE_DIVIDER 99999999L
#define UNO_SCORE 563L// I might eventually use this to guess which arduino you are benchmarking
#define MICRO_SCORE 559L
#define DUE_SCORE 3301L
#define MALLOC_SIZE 256
void printFloat(float value, unsigned long precision){
Serial.print(int(value));
Serial.print(".");
unsigned long frac;
if (value >= 0)
frac = (value - long(value)) * precision;
else
frac = (long(value) - value) * precision;
Serial.println(frac, DEC);
}
void setup() {
Serial.begin(57600);
long Millis=millis();
long increment = 0;
float f = 0.0f;
Serial.println("checking float performance using random");
for (; increment < ITER; increment++) {
f = random(0.0f, (float)increment);
}
Serial.print("rand performance time taken: ");
Serial.println(millis() - Millis);
Millis = millis();
Serial.println("now calculating PI using Newtonian method...");
long Millis2 = millis();
float pi = 0.0f;
float multiplier = 1.0f;
for (float incrementf = 0.0f, increment=0; increment < ITER; incrementf+=1.0f, increment++){
pi += 4.0f / (incrementf*2.0f + 1.0f)*multiplier;
multiplier *= -1.0f;
}
Serial.print("PI estimating time: ");
Serial.print(millis() - Millis2);
Millis2 = millis();
Serial.print(" PI estimate: ");
Serial.println(pi, 8);
Serial.println("About to test polar to rectangular coordinate conversion: ");
long Millis3 = millis();
float X = 0.0f;
float Y = 0.0f;
f = 0.0f;
for (long i = 0L; i < ITER/3; i++, f+=PI/1000.0f){
X = cos(f)*((float)i)/1000.0f;
Y = sin(f)*((float)i) / 1000.0f;
}
Serial.print("Polar to rect coords converting time: ");
Serial.println(millis() - Millis3);
Serial.print("X: ");
Serial.println(X, 8);
Serial.print("Y: ");
Serial.println(Y, 8);
Millis3 = millis();
Serial.println("now testing mem write speed(mallocing and freeing pointers):");
long Millis4;
for (long i = 0; i < ITER/4; i++){
char *j = (char*)malloc(MALLOC_SIZE);
char *f = j;
for (int i = 0; i < MALLOC_SIZE; i++){
*f = 'n';//just some random value to initialize the whole array of chars with
f++;
}
free(j);
}
Serial.print("Ram test finished in: ");
Serial.print(millis() - Millis4);
Serial.println(" milliseconds");
Serial.print("malloc size is: ");
Serial.println(MALLOC_SIZE);
Millis4 = millis();
long score = Millis + Millis2 + Millis3+Millis4;
score = SCORE_DIVIDER / score;
Serial.println("Your arduino's score is: ");
Serial.print(score);
}
void loop() {
}
-----------------------------------------
By the way, should I make myself a thread just for my old code(or just make this thread for all my code), cause I have a bunch of old codes I want to showcase(like pong for android, 2d minecraft in processing, 2048 in processing, a 2d platformer I made that I need to restore(well finish and fix not restore I don't have any way of doing that) because I made it on my school computer, so my comp doesn't have the working version and the version on my comp is outdated). Not all of it is polished or that good or anything, but some of my code(in my opinion) is not too bad.
Edit (Streetwalrus): merged double post.