I'm using Ubuntu 20.04 and am working on performance optimisations of some CFD code. When timing my code for quick feedback as to whether some modification is beneficial, there's often quite large run-to-run variance, due to background processes kicking in.
Because the code is using all available threads, any one thread being burdened with background tasks causes all others to wait.
Now my question is, whether or not there is a quick and easy way to temporarily halt background/non-essential tasks and therefore put my system into a kind of benchmark mode. Bash scripts, packages, built-in options, all is welcome.
One of the ways is to switch the system to multi-user target (this means without graphical session) reducing running processes to about 50:
or even switch to single user (about 10 processes will run)
And then run your application on these runlevels.
When benchmark finished - switch back to graphical session by