I have a program written in C++ that runs a number of for loops per second without using anything that would make it wait for any reason. It consistently uses 2-10% of the CPU. Is there any way to force it to use more of the CPU and do a greater number of calculations without making the program more complex? Additionally, I compile with C::B on a Windows computer. Essentially, I’m asking whether there is a way to make my program faster by increasing usage of CPU, and if so, how.
Share
Assuming your application has the power (
PROCESS_SET_INFORMATIONaccess right), you can useSetPriorityClassto bump up your priortiy (to the usual detriment of all other processes, of course).You can go
ABOVE_NORMAL_PRIORITY_CLASS(try this one first),HIGH_PRIORITY_CLASS(be very careful with this one) orREALTIME_PRIORITY_CLASS(I would strongly suggest that you probably shouldn’t give this one a shot).If you try the higher priorities and it’s still clocking pretty low, then that’s probably because you’re not CPU-bound (such as if you’re writing data to an output file). If that’s the case, you’ll probably have to find a way to make yourself CPU bound.
Just keep in mind that doing so may not be necessary (or even desirable). If you’re running at a higher priority than other threads and you’re still not sucking up a lot of CPU, it’s probably because Windows has (most likely, rightfully) decided you don’t need it.