Silly CPU Utilization Question

Started by
5 comments, last by Spoonbender 18 years, 7 months ago
I was trying to bring down the CPU utilization. I noticed something that I thought was strange. In a loop, I had to do some simple calculations before attempting to draw a point. I later realized that I could create a look-up table once in advance instead of doing the math in real time. I created a function to access the lookup table and set a container variable. I ran the app again and the utilization actually went up by 10%. Should the over-head of calling a function affect CPU usage this much?
Advertisement
By speeding up the calculation, you are allowing the CPU to do more work, so the utilization goes up. It wasn't just the overhead of a function call, but also eliminating whatever was being done in that function.
How big is your LUT? A cache miss can be more expensive than your simple calculations.
Ignore the value, it means next to nothing, you can make it say whatever you want depending on how often you call Sleep, what else is running on your machine etc. Doing a simple for loop adding numbers together will use 100% CPU if you dont call Sleep and a full blown 3d game running at 60fps could show 50% if you call sleep. Time your code by all means but dont use the CPU usage percentage as any sort of indictation how well/fast your code is running.
Thank you AP, for once I don't need to rant about this :P
Thanks for all the replies. Timing the calls seems like a better idea. I wanted to optimize my drawing before coding my A.I..
Or just don't optimize until you know you need it, and you can profile to see what's worth optimizing. :)

This topic is closed to new replies.

Advertisement