CPU usage seemingly capped (different from the 2019 question on this topic)

I want my Processing sketch to run with the CPU close to 100% utilisation, compared with the current 14%.

My Processing sketch trains a neural network for a puzzle where a mouse learns to evade a cat which is pursuing it. I was expecting the CPU to run fast (>80%) through the iterations, but what happens is that it uses almost no CPU: Task Manager shows two processes called Java ™ SE Binary, whose total CPU usage is typically 1 to 5% while the total CPU usage is about 14%. Memory is 76% used (650MB Microsoft Edge, 266 JAVA Platform SE binary, 100 MB Microsoft Word, a few small others).

This programme does calculations only and no drawing (not even setting the canvas background), and does not access any external resources eg a webpage.

My aim is for the programme to run the CPU nearer 100%, which will dramatically reduce the long times currently needed for training.

I have tried:

  • Changing the Windows power setting helped: System → power and battery → power mode. Changing to BALANCED or BEST PERFORMANCE had the same result, completing a generation of mice in 40% of the time used when I selected BEST POWER EFFICIENCY, although there is no difference to the total CPU usage or CPU usage by Processing (14% and 2% respectively, the same as when BEST POWER EFFICIENCY is selected).
  • Checking whether the programme is doing any unnecessary work (it isn’t).
  • Changing the task priority in Task Manager (can’t find how to do it in this version of Windows, but in any case it only makes a difference when the CPU is working hard)
  • This post discusses related issues. I don’t understand multiple threads in a programme, but I believe that they wouldn’t help in this case because each generation has to complete before the next one can be calculated. Processing seemingly capped at 35% cpu - Processing - Processing Foundation

The code is something like this:

/* Declarations and initialisations */

void setup () {

void draw() {

for (int generation = 0; generation < maxGenerations; generation++) {
   for (int i=0; i< maxIterations && ! mouse[i].finished; i++) {

Your program uses a single thread, which runs on a single CPU core.

Now, even when program fully utilises the core it runs on, the overall CPU usage is limited to 100 / # of cores%. In an 8 core/thread processor then, a single-threaded application can only use 12.5% CPU at most, which is similar to what you’re experiencing.