Still Alive

Yes, I’m still here.  Unfortunately, I haven’t been showing this site the love it deserves.

I have, however, updated some of the flash memory benchmarks with some new devices that have been recently purchased.  Interested, check them out here…
Micro SD, SD, Compact Flash and USB

How Fast is the Arduino Uno?

This was a question that popped into my mind lately.  Or rather, how efficiently does the Arduino Uno execute its C code?

I had read lots of articles of people switching to 32-bit chips on the Arduino platform in order to get better performance.  At first, I did not think much of this, but then started pondering why.  I mean, the 8-bit Uno can effectively execute one instruction per clock cycle giving it about 16 million instruction-per-second throughput.  Personally I think that is damn quick.  That beats my old Commodore Amiga computer by about four times (and that computer could play games, browse the Internet and run office productivity software.)  I started wondering if the Uno wasn’t actually attain its theoretical level of performance.  Does the C code compile so poorly that you lose a majority of the processing power?  To answer that question, I devised a little benchmark to see how efficiently the Arduino Uno can execute the mundane tasks associated with microcontrollers.

Here is the code.  The results are sent to the serial console.  (9600 baud)

// ---------------------------------
// Simple 'C' Benchmark for Arduino.
// ---------------------------------
// Date:  Aug. 3, 2016
// By: Brian Chhristian

// Clear the instruction counter.
unsigned long count = 0;

void setup()
    // There is nothing to initially setup.

void loop()
    count = 0;    // Clear the instruction counter
    int b = 0;    // Initialize result variable.
    // Get start time.
    unsigned long start_time = micros();

    // I tried picking some commonly used functions to simulate
    // what might be used in the real world.  I did not use any
    // crazy mathematics as they are probably no indicative of
    // what the average user may incorporate.

    count++;                                // Increment instruction counter for each line of code.
    for (unsigned int x=0; x<1000; x++)     // Do something 1,000 times.
        b = DoSomething(1);                  // Jump to a subroutine.

    // Get completion time.
    unsigned long end_time = micros();

    // Calculate elapsed time and IPS performance.
    unsigned long calc_time = end_time - start_time;
    unsigned long ips = count / (calc_time * 1E-6);

    // Send result via serial console and wait.
    Serial.print("Expected result (1): ");
    Serial.print("Lines of code executed: ");
    Serial.print("Execution Time (us): ");
    Serial.print("MIPS: ");
    Serial.println(ips / 1E6);

    // Wait before running again.

// Do some stuff in a subroutine.
int DoSomething(int y)
    int b = 0;

    for (int z=0; z<16; z++)   // Do something 16 times.
        int a = a + 1;

        if (a > 8)             // Lets do a compare.
            b = b + 10;        // How about some math.

    // Some more simple math and bit operations.
    b = b / 2;

    b = b & 8;

    b = b << 3;
    b = b - 63;
    return b;          // Let's return.

There really isn’t anything scientific about this benchmark.  I just did a number of loops with compares, bit operations and some simple math.  This is somewhat representative of the kind of code I generally use.  Hardly ever do I use complex math in my controller projects, so I left that kind of stuff out.

What I have found with this experiment is that, as a baseline, you can assume the Uno can execute around 2.5 million lines of code per second.  Definitely the kind of code you write can make a big difference, but I feel this gives me a good starting benchmark when determining whether or not something is feasible on the Uno.  (Now if only the “digitalWrite” routine was as quick…)

New USB Flash Drive Benchmarks

I just purchased two new USB Flash drives:  Lexar P20 64GB ($34) and Lexar S75 32GB ($11).  You can see their benchmarks here.

I am happy with the Lexar S75 32GB drive as it fits the bill for a larger capacity removable drive for cheap.  It’s not the fastest, but for $11 it gets the job done.

I also purchased the Lexar P20 64GB drive as a high-speed drive for quickly moving larger files around.  Wow, what a massive disappointment.  The specifications on Lexar’s website states 400MB/s read and 270MB/s write speeds.  I don’t get anything near that.  The measured read speed is fine at 341MB/s, but the write speed is paltry 39MB/s, way off the advertised 270MB/s numbers.  And if you send a collection of smaller files, be prepared for intolerable write speeds of 4.1MB/s.  (Yes that is four-point-one megabytes per second.)  This is unacceptable for a $34 drive, especially one advertised as being “faster with premium performance.”

Micro SD Card Benchmarks

I have started benchmarking the Micro SD Cards I have lying around.  I have been trying to determine which cards may be the best for use in some Raspberry Pi 2 projects I’m working on.  Thought I would post my findings.  I will also do the same for my SD and Compact Flash cards I have.  I might even put up some hard drive stats as well.  (But maybe not.  Hard drive benchmarks are mush easier to dins around the net than flash memory ones.)

Click here for the Micro SD Card benchmarks.