Electronic – Measuring firmware performance

cfirmwaremicrocontrollerpickit

I am using C compiler and PIC controllers.
I've been wondering about measuring the performance of the f/w code that we write. I have two versions of structures for the same code:

First one: using while

main()
  {..
   .. 
  initialization;

  while(check for conditions)
  {...
  ..
  .
  }

}

Second one: Using sequential states, or State machines.

main()
    {..
     .. 
    initialization;

    switch(state n)
    {...
    ..
    .
     }

    }

Well, my doubt is that whether I do either way, how will I measure which one is the best way to go forward?
I realized that the polling feature of the first method is often used in simple embedded systems. While the state machines of the second one is mostly used for single processor embedded systems.

  • How can I measure which firmware is best?
  • How can I monitor the statistics and related performance data?
  • Do compiler produces any valuable data to be checked, or is it debuggers that I must entrust?
  • What are the common tools available to measure the performance of a firmware?
  • Is it possible with a Debugger like Pickit3 /ICD3? I got a pickkit3 at hand.

I will be extremely grateful if you share your knowledge about dealing with firmwares and
clarifying my doubt.

Best Answer

If you use MPLAB, simply simulate with the "Stopwatch" function.

You can insert breakpoints and profile the code, accurate to the cycle. Very useful.

Of course you can look at the Memory Usage Gauge and see the code size when it's compiled.

It's also useful to look at the disassembled code, as others have suggested, especially in tight ISRs.

enter image description here