# What would be faster

**URL:** https://forum.kirupa.com/t/what-would-be-faster/257382
**Category:** programming
**Created:** [April 13, 2008, 3:37pm UTC](https://forum.kirupa.com/t/what-would-be-faster/257382 "2008-04-13T15:37:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ArmoredSandwich](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ArmoredSandwich](https://forum.kirupa.com/u/ArmoredSandwich)
#### Post date: [April 13, 2008, 3:37pm UTC](https://forum.kirupa.com/t/what-would-be-faster/257382/1 "2008-04-13T15:37:16Z")

</div>

Hey,

I’m creating an RTS, see my signature. And it’s going pretty well, obviously there is always the problem of lag. Now I wonder what to do. Should I see if a unit is on-screen and only render it when it is on-screen or should I just always render it.

Rendering would be copypixeling a 70x70 pixel picture to a bitmapdata that the user can’t always see. Obviously this is useless and uses precious cpu time. But maybe checking if a unit is on screen takes more cpu then the rendering part. Obviously the time spend on calculating if it’s on-screen is wasted when it appears that it is on-screen.

The user sees a screen of 500x500 pixels with the left top being the coordinate: (offSetX, offSetY). So the code would look something like this:

```auto

if (_x > offSetX && 
    _x < offSetX + 500 &&
    _y > offSetY &&
    _y < offSetY + 500)
    {
    render();
    }

```

What do you guys think? I think I’ll write a short program to see which one takes up the most cpu if you guys don’t know this exactly though 🙂 .

Thanks,

ArmoredSandwich AKA ImWithNoob.

Edit:

```auto

Testing copy pixels, we're gonna copy pixel a picture of: 70x70 100000 times
It took: 204 ms.
Testing the calculation too see if a unit should be rendered or not, 100000 times, unit is off-screen
It took: 155 ms.
Testing the calculation too see if a unit should be rendered or not, 100000 time, unit is on-screen.
It took: 241 ms.

```

Even if it was faster the unit would still have to render itself. So nope, it’s not faster. 😛
