I have never used Jest or a testing suit similar to it. But reading your question, it seems you are trying to find an optimized way to run your test suit and understand why there is a discrepancy in the usage with 50% CPU vs 90%.
Looking at the article, it seems unclear if this machine that is utilized is a shared machine with other resources (Development environment) or a dedicated server where you are running the tests.
I find more questions what hardware are you running (are you mimicking the article)? You mention an 8-core machine, but is it x86, ARM? Is hyperthreading enabled in your bios? Are you running services like antivirus/malware programs on the device (these run by default in the background)? What OS are you on, Windows Ubuntu, for these tests? What's the amount of memory in usage (Are you using DDR4 vs DDR5)? What disks are you using NVMe?
The article seems to be trying to benchmark between different devices, which is fine, and you will note the results are still varied as those devices run on different architectures (not to mention manufacturers).
Usually, there is no optimal answer to why --maxWorkers=50%
works better than, let's say, 70%, 80%, or 90%. If you run these on a server with 24 dedicated cores, 256GB Memory, and NVME Write incentive disks. I can say that your same test suit would run optimally at closer to 80% than at 50% (provided your tests are not big objects). It is also likely that Jest has some bad configuration in CPU usage (which is a possibility on how they read files, store, and run tests in parallel, where after a certain amount of threads, the complexity of parallel computing does not work), or just the cost of spawning child threads is high as mentioned by @Fcmam5.
I don't think anyone can answer your question about why 4 CPU threads are better than 7 CPU threads without re-running these tests in a similar environment. The answer could be simply that the DISK buffer is limited or that the Memory you hold for the object tests is being limited. Maybe some background processes are running that are sharing those last three threads, which leads to longer wait times than Jest running just on the idle four threads.
This is more relevant to the system in question, and you can only optimize it for your System. You can look for further optimization by tweaking the system in question. If you are simply trying to collect data I would recommend running these tests on dedicated servers for more conclusive data.