Execution Time

Does anyone know how long any of the Arduino commands take to execute? I'm working on a project and need to output data at 100 Hz (10 ms period) or more. Right now I'm testing out the capability of the board using two analog ports to read voltages and report them to the serial port to 4 decimal places and it takes about 41 ms. The calculations may chew up a bunch of time, but eventually I'll be using a floating point voltage in a calibration equation and outputting a PWM signal and/or send data with the Ethernet shield (which if anyone has any good information on, I'd also appreciate). Please advise. Thanks!

The baud rate, and number of bytes that you are sending over the serial port may be a significant factor in your timings. Work out the theoritical minimum time for transmissions as bytes * 10 bits (8 data + 1stop + 1start) * 1 / baud rate, and see how much of this accounts for your 40mS.

e.g. at 9600 baud, sending 16 bytes would be

16 * 10 * 1 / 9600 = 16mS.

If you have access to an oscilloscope, you could easily get precise timings by setting a digital out high before an operation, and low immediately after it, and connect the scope probe to that output.

I agree with setting a pin high/low. I wrote a tone generating routine that has a loop that delays then flips a pin. If I hookup a frequency counter, I see the speed/frequency of the pin output.

I declare a pin like so:

#declare myPIN 12
boolean Tone_HighLow = LOW;

digitalWrite(myPIN, Tone_HighLow);
Tone_HighLow = !Tone_HighLow; // flips the pin status each time

digitaWrite takes almost 5 microseconds to turn a pin on and off. That's around 40 times longer than it takes using low level instructions to turn io pins on and off (using fast but unintuitive direct port io) , but short compared to delays using the serial port.

Minimize time spent sending serial data by using short messages and a high baud rate.

Floating point is much slower than integer calculations, try to use long integers instead of floats if you can.
(123.456 + 0.789 )* 2 is much slower than (123456 + 789)* 2