# High cpu usage

**URL:** <https://discourse.libsdl.org/t/high-cpu-usage/4437>\
**Category:** SDL Development\
**Created:** [May 18, 2001, 10:00pm UTC](https://discourse.libsdl.org/t/high-cpu-usage/4437 "2001-05-18T22:00:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave1](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@Dave1](https://discourse.libsdl.org/u/Dave1)\
**Post date:** [May 18, 2001, 10:00pm UTC](https://discourse.libsdl.org/t/high-cpu-usage/4437/1 "2001-05-18T22:00:27Z")

</div>

I put together a test program that just bounces 2 sprites around in a  
window. They bounce off each other and off the sides of the window, and  
it has a simple gravity caclulation. It has a collsion response function  
that is fairly sophisticated but only runs when there is indeed a  
collision, and my collision detection algorithm is linear and very  
efficient.

However, my CPU usage is always in the 80-90% range when the program is  
running. I had some of my calculations as floating point operations, and  
I converted them to use all integer ops where possible, and that seems to  
have increased my framerate from 50fps to 75fps or so, but no reduction in  
CPU load. Is this normal behavior? Could this be caused by the blitting?  
I do a SDL\_DisplayFormat() on the sprites after loading them so I assume  
its not because SDL has to convert the images each blit. If anyone is  
interested in seeing the code I put a tarball at  
[http://meatloop.andover.net/~count/bounce-051801.tar.gz](http://meatloop.andover.net/~count/bounce-051801.tar.gz). Thanks 🙂  
dave—

Vanity. Definitely my favorite sin.

---

<div class="post-metadata">

**Author:** ![David\_MacCormack](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/7993a0/32.png) [@David\_MacCormack](https://discourse.libsdl.org/u/David_MacCormack)\
**Post date:** [May 19, 2001, 1:40am UTC](https://discourse.libsdl.org/t/high-cpu-usage/4437/2 "2001-05-19T01:40:10Z")

</div>

> I converted them to use all integer ops where possible, and that seems to  
> have increased my framerate from 50fps to 75fps or so, but no reduction in  
> CPU load. Is this normal behavior?

Well I’m no expert, but yes, I’d say it’s normal.

while(1) {  
/\* do nothing \*/  
}

will also use your push your CPU to the max. By changing the code in the  
middle (e.g. from floating point ops to integer ops), all you could ever  
hope to achieve is higher framerates. If you’re concerned about hogging  
the box, add an SDL\_Delay(10).

Make sense :)?

DaveOn Fri, 18 May 2001, Dave wrote:

## –

David MacCormack  
@David_MacCormack
