Recently, I attempted some simple operations on image pixels. The speed (or rather lack of) really surprised me. So, I decided to educate myself about the speed of actual operations on my FEZ Spider board.
My main tool is: [italic]Microsoft.SPOT.Hardware.Utility.GetMachineTime()[/italic]
As best as I can tell, it is reasonably accurate. If nothing else, it produces consistent results and over periods like seconds, it seems sufficiently accurate. In order to get more reliable data, I ran my tests in a loop 1000 times, and then subtracted the “overhead” times that I already collected, like for example the time it takes to execute an empty loop. An example of my timing test (where iterations is const int that has same timing characteristics of hard-coding 1000 into the loop–I tested it):
start = Microsoft.SPOT.Hardware.Utility.GetMachineTime();
for( x = 0; x < iterations; x++ )
{
y = 5;
}
data.AssignmentConst = Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks - start.Ticks;
data.AssignmentConst /= iterations; // get ticks for single iteration
data.AssignmentConst /= 10; // get microseconds for single iteration
data.AssignmentConst -= data.SimpleForLoop; // subtract known overhead
accumulator.AssignmentConst += data.AssignmentConst; // accumulate with previous results
data.AssignmentConst = accumulator.AssignmentConst / additions; // keep average as our result
Some of the results I got (in microseconds per single op, rounded down):
Simple for loop: 54
Assignment of const ( y = 5 ): 7
Assignment of var ( y = z ): 11
Multiply constants ( 3 * 5 ): 0
Multiply with var ( 3 * z ): 10
Compare two constants ( 3 > 5 ): 11
Compare with var ( y > 5 ): 41
Compare 2 vars ( y > z ): 45
For a microprocessor advertised to run at 72MHz, this seemed a bit excessive. After additional digging, I queried the processor for its speed with: Microsoft.SPOT.Hardware.Cpu.SystemClock
It says: 18000000
Which I presume means 18MHz. Could someone explain to me why the reported speed is 4 times less than advertised speed? I’m also curious why it takes ~200 clock cycles to step through
if ( 3 > 5 ) ;
Comments?