Can someone with a Fez Hydra do me a favor?

@ rgm

The code you posted runs only 20k iterations. In other words, 1/5th the number of iterations Gralin’s code runs.

In addition, hard-coding a constant value for loop comparison has a notable performance improvement over using a variable (e.g. myArray.Length).

–Edit–

Also, if you look for the post I made a week or two ago, about FEZ Spider timing, you’ll see some baseline results that I got. For a simple empty for-loop iteration, you’ll need 55us or so. So, 100k iterations would end up taking 5.5s. And that’s a completely empty loop, with a constant comparison. Hydra is supposed to be twice as fast as Spider, but you also do quite a few more operations in your for-loop, so the results are pretty consistent.

Moondragon…

Yes it is interesting how you can speed up the loops. It is especially important for me because I have wasted a month on 10 different controllers trying to sample 6 analog inputs at 2-3 kHz…mind you these were all non C platforms with the exception of the Arduino. Usually the memory was not the bih´ggest problem it was buying a controller only to find out the SD card library was incomplete (PINGUINO AND UNO32) or that it was not fast enough (Duinomite…although my all time favorite)…

What was very striking was how the memory of the hydra changes the way you can implement a data logger. Normally on most low end microcontrollers you have 2-50 kb to play with (which I am sure you know)…the dilemna is what do you do when you want to sample at a high rate and the SD slows you down…you just cannot do it…I sample in bursts and this think ROCKS!!!

This is why I LOVE THE HYDRA!!!

Not done anything yet with a FEZ but in the PIC world i have used these to overcome SD card slowness.
http://www.ramtron.com/products/nonvolatile-memory/serial-product.aspx?id=109
There are many capacities available.
They send out free samples too.

Your handle is a misnomer Brainless!

I have messed around with pic but I have found it pretty challenging!

Interesting. Although I question if DateTime.Now.Ticks is a scientific way of counting time. Here are my results:

Run #1. compile in debug target 4.60 second


            for (int i = 0; i < 20000*5; i++)
            {
                myInt[i] = ain.Read();
            }

Run #2. compile in release target 4.29 second


            for (int i = 0; i < 20000*5; i++)
            {
                myInt[i] = ain.Read();
            }

Run #3. compile in release target 3.31 second


            for (int i = 0; i < 20000*5; i++)
            {
                ain.Read();
            }

Run #4. compile in release target 2.35 second


            for (int i = 0; i < 20000; i++)
            {
                ain.Read();
                ain.Read();
                ain.Read();
                ain.Read();
                ain.Read();
            }

Run #5. compile in release target 0.76 second


            for (int i = 0; i < 20000; i++)
            {
                myInt[i] = ain.Read();
                myInt[i++] = ain.Read();
                myInt[i++] = ain.Read();
                myInt[i++] = ain.Read();
                myInt[i++] = ain.Read();
            }

I don’t think you can explain this by looking at the c# code. Maybe dive into the compiled bytecode?

run #6, release target 0.04 second


            int i = 0;
            while (i < 1000)
            {
                myInt[i++] = ain.Read();
                myInt[i++] = ain.Read();
//same line 100 times,
                myInt[i++] = ain.Read();
            }


And then I realized in your post about the 0.87second result the ain.Read() was actually executed only 2000 times.

So the conclusion is the ain.Read() is roughly 0.02ms, a for/while condition check adds 0.013ms, and an integer memory addressing adds 0.01 ms. The results have been quite consistent with all the tests above. In other words if we ignore all other distractions the sampling rate of one analog input is around 50k Hz, or once per 20 microseconds.

Kurutoga

I can check when I get to the office but I believe I was actually sampling at 300 to 400 kHz. I was using six channels though. I was very amazed at this speed. Now the problem is finding suitable batteries to run for 4 to 7 days…

We will see…