One of the key success factors of Dart is its performance. The Dart VM has a built-in optimizer to increase the execution speed. This optimizer needs a certain amount of execution time before it has enough information to do its work. This is no problem for an app in production, but when testing, you must ensure this condition is met. In this recipe, we are going to focus on how to best benchmark your application.
The benchmark_harness
package from the Dart team is built specifically for this purpose. Add it to the pubspec.yaml
file and import it in your code. We will illustrate this with the template_benchmark
app. Also, make sure that all the issues detected by the checked mode are solved (because these could have an effect on the execution speed) and that the app is run in the production mode (refer to the Setting up the checked and production modes recipe in Chapter 1, Working with Dart Tools).