This approach is done in front of a Drupal background but I think it can be generally used in any project with behat and more widely in any project with CI or any automated testing. I took some inspiration from https://www.lambdatest.com/blog/how-to-measure-page-load-times-with-selenium/
We have a setup where we have Drone CI and run behat tests as part of the pipeline.
I have created a behat context PerformanceTimingContext for this. To use it in a composer based project:
composer require miiimooo/behat-tools:4.x
Then enable it in your behat configuration:
default: suites: default: contexts: ... - miiimooo\BehatTools\Context\PerformanceTimingContext
A simple test looks like this:
When running this there is now new output attached to each scenario:
Since this is running as part of CI there is a history of performance and whenever there is a claim that the site is really slow or someone has improved something there is a place to look what has actually changed.
The CI runs not just one project but many and performance can vary depending on how many other tasks are running.
In reality the numbers vary quite a bit from build to build. In Drone CI it's possible to re-run a previous commit as a new build (Restart build).
One major area of improvement is presentation. There is a slack notification plugin for Drone CI that is used for reporting failure/success in a dedicated channel. It would be useful to have the average performance of the whole test there as well, together with standard deviation.