in this post http://jacksondunstan.com/articles/2329 , Jackson measure the performances reading andwriting values in alchemy versus with a vector. It came up with some surprising results, so I decided to do my own test with apparat so I can test the same thing with older flashPlayers. I modified the code so the same number of local […]

~ read more ~## Monthly archives for July, 2013

# integer Math.abs trick

lets try to replace the slow abs = Math.abs(integerVal); The obvious way, abs = j>31)^j)-(j>>31); here why it works: when j>0, j>>31 gives 0, so (0)^j gives j, and j-0 is j when j>31 gives -1, and (-1)^j invert all bits on j, so if the value was -5 , or 1111.1111.1111.1111.1111.1111.1111.1011 , ~5 gives […]

~ read more ~# integer sign trick

How to get the sign of an integer fast ? The obvious way: var sign:int = (intval0)?1 : 0); Can we do better? if we shift 31 bits to the right , we can extract the sign, (val>>31) : if the val=0: 0 (-val>>>31): if the val >0 :1 if the val >31)+(-intval>>>31); this version […]

~ read more ~# Math.sin tricks

Math.sin is slow, we have many options to optimize it, a good post from Jackson dunstan “Even Faster Trig Through Inlining” show lots of methods (http://jacksondunstan.com/articles/1213) But there is a major problem with all the proposed methods : it only works for a certain range of angle, and if you want to use those functions […]

~ read more ~# sqrt trick

To compute the sqrt, we can use the Newton-Raphson method to converge to a sqrt. Newton serie is: x_(i+1) = x_i – f(x_i)/f’(x_i) for the sqrt we have: sqrt(n) = x or n = x^2 our newton function f(x) becomes: f(x) = x^2 – n. and first derivative: f’(x) = 2x; with our particular f(x), […]

~ read more ~
## Recent Comments