# Math.floor Vs bit shifting Vs int

**URL:** https://forum.kirupa.com/t/math-floor-vs-bit-shifting-vs-int/294625
**Category:** flash
**Created:** [August 17, 2009, 6:03pm UTC](https://forum.kirupa.com/t/math-floor-vs-bit-shifting-vs-int/294625 "2009-08-17T18:03:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![rumblesushi](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rumblesushi](https://forum.kirupa.com/u/rumblesushi)
#### Post date: [August 17, 2009, 6:03pm UTC](https://forum.kirupa.com/t/math-floor-vs-bit-shifting-vs-int/294625/1 "2009-08-17T18:03:22Z")

</div>

I just ran some tests on round numbers.

In preparation for getting max performance from AS3, I want to test as many areas as possible.

All I did was generate a rounded random number a million times per frame, and record the time step in milliseconds.

These are the results -

Math.floor = 303 ms

bitshifting = 220 ms

int = 205 ms

Now the strangest part is having a non rounded random number generated a million times per frame netted an average time of 195 milliseconds, faster than using int as a random number. It must simply be that because Math.random isn’t returning an integer, some form of conversion of taking place for your variable to be an integer.

Incidentally, using a Number instead of integer for the looping variable decreased performance minimally, just a few milliseconds.

So simply having your variable as an integer, and using no rounding at all produces the fastest results if you want a round number.

So where practical, just do that.

Remember though, there are many other areas in Flash to dramatically increase performance. Being that we’re talking about a million iterations per frame, the difference in performance is not exactly dramatic here. One is not even twice as fast as another, over a million iterations.

But still, every bit of juice counts in Flash 😉
