Best way to peg the CPU at 100%?

75 points buff_001

I just need a very simple way to peg the CPU and all cores at 100%. This is required to simulate extreme CPU load while running some other programs.

This is what I've come up with

[dependencies]
num_cpus = "1.16.0"

fn main() -> ! {
    for _ in 0..num_cpus::get() {
        std::thread::spawn(|| {
            let mut x: f64 = 0.0;
            loop {
                // Perform some simple floating-point computation
                x = (x + 1.0).sin();
            }
        });
    }
    loop {}
}

I added some f64 calculations since llvm seems to optimize-away just plain loop {}

Is there a better way? Maybe something that also tests registers, cache, etc? Basically, I want my CPU to be fully saturated so that I can test various latencies with some other programs that I am writing running at the same time.