Main Site Documentation

FEZ Spider operation costs


#1

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?


#2

I do not believe that Microsoft.SPOT.Hardware.Cpu.SystemClock gives a meaningful number.


#3

I advise to use RLP for image processing.

Check this demo code:

http://code.tinyclr.com/project/295/rlp-bitmap-rotation-demo/


#4

@ Architect

That is a very useful advice. I was not aware of RLP up to this point.

But it doesn’t change the fact that Spider takes 54us to execute a single iteration of an empty loop. That seems awfully slow for a 72MHz processor. Assuming that the processor runs at that speed, it means it would take almost 4000 operations for a simple addition, assignment, comparison and some overhead logic.


#5

You are welcome!

Unfortunately it is not that simple. MF is not real time. To much is going on behind the scenes in the .Net managed world -(allocations,checks,garbage collection runs,etc,etc).

That is why GHI came up with RLP.


#6

Let us not forget that C# is interpreted in the MF world. :smiley:


#7

This should help http://www.tinyclr.com/faq/