I do not know if people will see this, but I ran the benchmark on the Arduino 101, using the IDE 1.6.9. I also added the feature to time an analog-write / PWM on pin 9 and I compensated for the time it took to map the values (by timing them as well).
These are my results for the Arduino 101, doing 5000 iterations as well:
Digital Write: 1.5634 Microseconds (.31 nanoseconds per execution)
Digital Read: 1.3131 Microseconds (.26 nanoseconds per execution)
Analog Read: 27.9999 Microseconds (5.59 nanoseconds per execution)
Analog Write (PWM): 2.2391 Microseconds (.44 nanoseconds per execution)
Mapping 0-5000 to 0-255: 1.9063 Microseconds (.38 nanoseconds per execution)
This is the code I used, after modifying it for the mapping and PWM timers. Credit goes to the original Author Riva.
/* Benchmark V2.0 02-June-2015 */
#define targetBoard "Arduino 101"
#define ideVersion "Arduino IDE v1.6.9"
#define analoguePin A0
#define digitalPin 9
#define ledPin 1
#define loopCount 50000 // Max 65535
void setup() {
Serial.begin(115200);
while (!Serial) ;
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,LOW);
pinMode(analoguePin,INPUT);
}
void loop() {
unsigned long startTime;
unsigned long totalTime;
unsigned int x;
int ar;
int y;
Serial.print(F(targetBoard));
Serial.print(F(" I/O Speed Tests Over "));
Serial.print(loopCount, DEC);
Serial.print(F(" Iterations. Compiled Using "));
Serial.println(F(ideVersion));
Serial.flush();
delay(1000);
// Digital Write
pinMode(digitalPin,OUTPUT);
digitalWrite(ledPin,HIGH);
startTime = micros();
for (x = 0; x < loopCount; x++){
digitalWrite(digitalPin,HIGH);
digitalWrite(digitalPin,LOW);
}
totalTime = micros() - startTime;
digitalWrite(ledPin,LOW);
Serial.print(F("Digital Pin Write Takes About "));
//Serial.print(totalTime / 2);
//Serial.print(F(" Microseconds And Each 'digitalWrite' Took About "));
Serial.print((float)totalTime / (float)loopCount / 2.0, 4);
Serial.println(F(" Microseconds."));
Serial.flush();
delay(1000);
// Digital Read
pinMode(digitalPin,INPUT);
digitalWrite(ledPin,HIGH);
startTime = micros();
for (x = 0; x < loopCount; x++){
ar = digitalRead(digitalPin);
}
totalTime = micros() - startTime;
digitalWrite(ledPin,LOW);
Serial.print(F("Digital Pin Read Takes About "));
Serial.print((float)totalTime / (float)loopCount, 4);
Serial.println(F(" Microseconds."));
Serial.flush();
delay(1000);
// Analogue
digitalWrite(ledPin,HIGH);
startTime = micros();
for (x = 0; x < loopCount; x++){
ar = analogRead(analoguePin);
}
totalTime = micros() - startTime;
digitalWrite(ledPin,LOW);
Serial.print(F("Analogue Pin Read Takes About "));
//Serial.print(totalTime / 2);
//Serial.print(F(" Microseconds And Each 'digitalWrite' Took About "));
Serial.print((float)totalTime / (float)loopCount, 4);
Serial.println(F(" Microseconds."));
Serial.flush();
delay(1000);
//AnalogWrite
digitalWrite(ledPin, HIGH);
startTime = micros();
for (x = 0; x < loopCount; x++){
analogWrite(9, map(x, 0, loopCount, 0, 255));
}
totalTime = micros() - startTime;
digitalWrite(ledPin, LOW);
Serial.print(F("PWM Write Takes About "));
//Serial.print(totalTime / 2);
//Serial.print(F(" Microseconds And Each 'digitalWrite' Took About "));
Serial.print((float)totalTime / (float)loopCount, 4);
Serial.println(F(" Microseconds."));
Serial.println();
Serial.flush();
delay(1000);
//mapping
startTime = micros();
for (x = 0; x < loopCount; x++)
{
y = map(x, 0, loopCount, 0, 255);
}
totalTime = micros() - startTime;
Serial.print(F("Mapping Takes About "));
//Serial.print(totalTime / 2);
//Serial.print(F(" Microseconds And Each 'digitalWrite' Took About "));
Serial.print((float)totalTime / (float)loopCount, 4);
Serial.println(F(" Microseconds."));
Serial.println();
Serial.flush();
delay(1000);
}
Benchmark_IO.ino (3.1 KB)
101 Benchmark.txt (505 Bytes)