In my presentation at ARM TechCon 2013 last week "ARM Cortex-M for Beginners", someone asked a question of “Is there any advice for getting the best performance? Which C compiler to use?
This is a very interesting question. One page of my slides showed the Dhrystone (version 2.1) and CoreMark results for various Cortex-M processors, assuming zero wait state memory. However, the actual performance when running these benchmarks on specific microcontroller devices depends on the compiler and compilation options used, memory system wait states, etc. Depending on the microcontroller setup and tool chain used for the compilation, you can get different results.
To make things more complicated, the results of running these benchmarks might have no correlation to the performance of running your own application. These types of generic benchmarks are often focused on general data processing, and your applications might have completely different types of operations such as I/O controls, OS context switching, etc. As a result, the exact performance of your applications on different processors might not match the relative performance of running CoreMark or Dhrystone.
If your application requires high performance (again this is a vague term) then in an ideal world you should benchmark different devices and tools using your own application code. Bear in mind that even if a microcontroller can provide the required processing performance, you still need to leave additional performance head room in case some processing time is consumed by a large number of interrupt requests in short time. If you need to spend lots of time optimizing the code to get the performance to the required level, you might have chosen the wrong device. And when you compile for the maximum performance, the code size could increase significantly due to unrolling. In many cases, it is easier and safer to get a higher performance microcontroller at similar cost, while providing the extra performance headroom.
Back to the choice of C compilers, there is no golden answer. Compiler A might be better in CoreMark, and compiler B might be better in Dhrystone, and the results can change overtime when different versions of the toolchains are released. Don’t forget that the performance of the generated code is only one aspect of choosing your development tools. There are many other factors to consider: license cost, debug features, device support, reliability, technical support, code size, code editor and even middleware bundles.On the brighter side, you can download the evaluation versions of most of the popular tool chains and try them out before you decide which one to buy. There are a number of low cost evaluation boards available which can work with multiple tool chains. So you can try out the same program, on the same board, with different C compilers easily.Some of the C compiler vendors have application notes or documents to explain how to select the right compilation options to get the best performance. For example, Keil Microcontroller Development Kit (MDK) has application note 202 : MDK-ARM Compiler Optimization (http://www.keil.com/appnotes/docs/apnt_202.asp)In summary, when choosing your development tool chain, remember that performance is only one of the many factors. And if your application could fail unless you compile the code with the maximum speed optimizations, think again to see if you are using the right microcontroller device .