I recently bought an Arduino Due, and I worked up this code to compare the speeds of Due and Uno.
#include <stdint.h>
void setup() {
/*
Results
My Due = 7425986u = 7427m
My Uno = 24591260u = 24591m
*/
// put your setup code here, to run once:
pinMode(13, OUTPUT);
Serial.begin(115200);
while(!Serial);
Serial.println("Start");
float a = 0.2;
float b = 0.3;
/* 0 to 4,294,967,295 */
uint32_t startMicros = micros();
uint32_t startMillis = millis();
for(uint32_t i=0;i<10000;i++){
for(uint32_t j=0;j<100;j++){
a = b = (digitalRead(2)+2);
b = a*(digitalRead(2)+1);
a = b*(digitalRead(2)-1);
a = a*1.5*(digitalRead(2)-5);
b = b*1.5+(digitalRead(2)-200);
a = b*a;
if(a>2.3 && b<0.5){
digitalWrite(13, HIGH);
}else{
digitalWrite(13, HIGH);
}
}
}
Serial.print("Micros = ");Serial.println(micros()-startMicros);
Serial.print("Millis = ");Serial.println(millis()-startMillis);
Serial.println("End");
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(100);
}
Given the clock speed and 32 bit controller of the due. I has hoping for a difference of 84/16 * 4 = 21 Times. But my experiment returned that my Due is only 3.3 times faster than my uno.
Am I missing something here? I am starting to suspect that I have received a fake Due. Can anybody post their result by running this code.