node環境だとMath.floor使うのと<<でビット演算してもあんま変わんない
オライリー本で「小数点以下の切り捨てはMath.floor使うより<<でビット演算したほうが早いよ」と書いてあったけど、
nodeで実行してみるとあんまり差がない。
pi = 3.14 bitshift = -> pi<<0 floor = -> Math.floor(pi) funk_timer =(fn)-> start = new Date for i in [0..100000000] fn() console.log (new Date - start) console.log "bitshift -----" funk_timer bitshift console.log "Math.floor -----" funk_timer floor
あんまり差がない。
coffee pi.coffee bitshift ----- 1337 Math.floor ----- 1312
速度差が出るのはブラウザ上だけみたい。