user4830: I am trying to run a test of the speed of an Arduino, and how it's affected by different temperatures. Does the following code assess this properly? 
long num = 0;
long startTime = 0;
long endTime = 0;
int duration = 0;
String buffer;

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

void loop(){
  startTime = millis();
  benchmark();
  endTime = millis();
  duration = endTime - startTime;
  Serial.print(startTime);
  Serial.print(", ");
  Serial.print(endTime);
  Serial.print(", ");
  Serial.println(duration); 
}

void benchmark() {
  num = 0;
  for(num = 0; num < 1000000; num++);
}

I'm using an Uno, if that matters.

user881: Quite simply, you cannot measure the stability of a device using routines that themselves depend on the device clock.
To do this properly you need an external measuring device that has a clock source at least 10 times more stable than the Arduino xtal. Most frequency counters would qualify.
Just set up a timer to provide a constant output frequency, and attach the counter to the pin.

user2881: No.
That is because millis will be equally affected by any frequency change (due to temperature) as the benchmark code. You would need an external clock source that is precise enough.
Note that temperature doesn't have that big an impact on crystal oscillators. Somewhere around 10ppm between -20 and +20 degrees C. The crystal itself is probably already 50ppm precision to start with (higher precision ones are more expensive).

4830: <p>I am trying to run a test of the speed of an Arduino, and how it's affected by different temperatures. Does the following code assess this properly? </p>

<pre><code>long num = 0;
long startTime = 0;
long endTime = 0;
int duration = 0;
String buffer;

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

void loop(){
  startTime = millis();
  benchmark();
  endTime = millis();
  duration = endTime - startTime;
  Serial.print(startTime);
  Serial.print(", ");
  Serial.print(endTime);
  Serial.print(", ");
  Serial.println(duration); 
}

void benchmark() {
  num = 0;
  for(num = 0; num &lt; 1000000; num++);
}
</code></pre>

<p>I'm using an Uno, if that matters.</p>
 881: <p>Quite simply, you cannot measure the stability of a device using routines that themselves depend on the device clock.</p>

<p>To do this properly you need an external measuring device that has a clock source at least 10 times more stable than the Arduino xtal. Most frequency counters would qualify.
Just set up a timer to provide a constant output frequency, and attach the counter to the pin.</p>
 2881: <p>No.</p>

<p>That is because millis will be equally affected by any frequency change (due to temperature) as the benchmark code. You would need an external clock source that is precise enough.</p>

<p>Note that temperature doesn't have that big an impact on crystal oscillators. Somewhere around 10ppm between -20 and +20 degrees C. The crystal itself is probably already 50ppm precision to start with (higher precision ones are more expensive).</p>
