Skip to content

Instantly share code, notes, and snippets.

@azu
Created March 2, 2009 16:28
Show Gist options
  • Save azu/72842 to your computer and use it in GitHub Desktop.
Save azu/72842 to your computer and use it in GitHub Desktop.
// 絶対値はMath.absよりシフト演算の方が早い
// http://actionscript.g.hatena.ne.jp/ConquestArrow/20070621/1182359767
abs = function(x){
return (x ^ (x >> 31)) - (x >> 31);
};
console.time("1");
for(i=0;i<100000;i++){
abs(-i);
}
console.timeEnd("1")
console.time("2");
for(j=0;j<100000;j++){
Math.abs(-j);
}
console.timeEnd("2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment