From subsecret
Jump to: navigation, search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:
|}
|}


Benchmark of digital sensor read (100000 digitalRead()) (internal time used for measurement)
{| class="wikitable sortable"
!Model
!Duration (ms)
|-
|Arduino 101
|
|-
|Arduino Mega 2560 (clone)
|
|}
Benchmark of analog sensor read (100000 analogRead()) (internal time used for measurement)
{| class="wikitable sortable"
!Model
!Duration (ms)
|-
|Arduino 101
|
|-
|Arduino Due (clone)
|
|-
|Arduino Mega 2560 (clone)
|
|}


Benchmark of pi calculation (internal time used for measurement)
Benchmark of pi calculation (internal time used for measurement)
Line 150: Line 122:
  }
  }


Analog Read program
Analog Read program  


void setup() {
void setup() {
  pinMode(2, INPUT);
  pinMode(2, INPUT);
  Serial.begin(9600);
  Serial.begin(9600);
}
}
 
void loop() {
void loop() {
 
  int readZero = 0;
  int readZero = 0;
  int reads = 0;
  int reads = 0;
  unsigned long start = millis();
  unsigned long start = millis();
  while (true) {
  while (true) {
 
    if (analogRead(2)==0) {
    if (analogRead(2)==0) {
      readZero++;
      readZero++;
    }
    }
    if (reads == 10000) {
    if (reads == 10000) {
      break;
      break;
    }
    }
    reads++;
    reads++;
  }
  }
  unsigned elap = millis() - start;
  unsigned elap = millis() - start;
  Serial.println(elap);
  Serial.println(elap);
  Serial.print("Zeros: ");
  Serial.print("Zeros: ");
  Serial.println(readZero);
  Serial.println(readZero);
 
}
}




Digital read benchmark program
Digital read benchmark program


void setup() {
void setup() {
  pinMode(2, INPUT);
  pinMode(2, INPUT);
  Serial.begin(9600);
  Serial.begin(9600);
}
}
 
void loop() {
void loop() {
 
  int readZero = 0;
  int readZero = 0;
  int reads = 0;
  int reads = 0;
  unsigned long start = millis();
  unsigned long start = millis();
  while (true) {
  while (true) {
 
    if (!digitalRead(2)) {
    if (!digitalRead(2)) {
      readZero++;
      readZero++;
    }
    }
    if (reads == 10000) {
    if (reads == 10000) {
      break;
      break;
    }
    }
    reads++;
    reads++;
  }
  }
  unsigned elap = millis() - start;
  unsigned elap = millis() - start;
  Serial.println(elap);
  Serial.println(elap);
  Serial.print("Zeros: ");
  Serial.print("Zeros: ");
  Serial.println(readZero);
  Serial.println(readZero);
 
}
}

Latest revision as of 07:49, 15 December 2017

Benchmark of internal time precision

Model range of 60 sec delay() call avg. duration of 60 sec delay() call
Arduino 101 59998-59999 59998.5625
Arduino Due (clone) 60000-60001 60000.5143
Arduino Mega 2560 (clone) 59989-59994 59991.75
Arduino Mega 2560 (clone 2) 60470-60471 60470.25


Benchmark of pi calculation (internal time used for measurement)

Model Size of double Duration (sec) Pi value
Arduino 101 8 3.879 3.1415936536
Arduino Due (clone) 8 16.512 3.1415936536
Arduino Mega 2560 (clone) 4 58.338 3.1415972709



Test programs: Python program for measuring response time

import time
import serial
def millis():
    return int(round(time.time() * 1000))
ser = serial.Serial('/dev/ttyACM0', 9600)
while True:
	start = millis()
	data= "recv: "+ser.readline()	
	end = millis()
	print (end-start)
	print data


Time precision benchmark

void setup() {
  Serial.begin(9600);
}

void loop() { 

  while (true) {
    unsigned long start = millis();
    delay(60000);
    unsigned elap = millis() - start;
    Serial.println(elap);
  }
}

Pi benchmark (adapted from http://forum.arduino.cc/index.php?topic=138802.0)

#define ITERATIONS 1000000L    // number of iterations

void setup() {
  Serial.begin(9600);
}

void loop() {

  unsigned long start, time;
  unsigned long niter = ITERATIONS;

  double x = 1.0;
  double pi = 1.0;
  unsigned long i = 0;
  start = millis();
  Serial.print("Sizeof(double)=");
  Serial.print(sizeof(double));
  Serial.println();

  for ( i = 2; i < niter; i++) {
    x *= -1.0;
    pi += x / (2.0 * (double)i - 1);
  }

  time = millis() - start;

  pi = pi * 4.0;

  Serial.print("# of trials = ");
  Serial.println(niter);
  Serial.print("Estimate of pi = ");
  Serial.println(pi, 10);

  Serial.print("Time: ");
  Serial.print(time);
  Serial.println(" ms");
  Serial.println();
  delay(5000);
}

Analog Read program

void setup() {
  pinMode(2, INPUT);
  Serial.begin(9600);
}

void loop() {

  int readZero = 0;
  int reads = 0;
  unsigned long start = millis();
  while (true) {

    if (analogRead(2)==0) {
      readZero++;
    }
    if (reads == 10000) {
      break;
    }
    reads++;
  }
  unsigned elap = millis() - start;
  Serial.println(elap);
  Serial.print("Zeros: ");
  Serial.println(readZero);

}


Digital read benchmark program

void setup() {
  pinMode(2, INPUT);
  Serial.begin(9600);
}

void loop() {

  int readZero = 0;
  int reads = 0;
  unsigned long start = millis();
  while (true) {

    if (!digitalRead(2)) {
      readZero++;
    }
    if (reads == 10000) {
      break;
    }
    reads++;
  }
  unsigned elap = millis() - start;
  Serial.println(elap);
  Serial.print("Zeros: ");
  Serial.println(readZero);

}