Math.floor vs Math.round vs parseInt vs Bitwise
JavaScript performance comparison
Info
Rounding in all form possible
Preparation code
<script>
Benchmark.prototype.setup = function() {
var a = Math.random() * 1000;
var b = Math.random() * 1000000;
var c = Math.random() * 1000000000;
var d = Math.random() * 10;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test  Ops/sec  

Math.floor 

pending… 
Math.round 

pending… 
parseInt 

pending… 
Bitwise  

pending… 
Bitwise 

pending… 
Bit flipping 

pending… 
zerofill right shift 

pending… 
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit
to the URL. Here’s a list of current revisions for this page:
 Revision 1: published by Felladrin
 Revision 2: published by Batiste and last updated
 Revision 5: published by JohnDavid Dalton and last updated
 Revision 6: published
 Revision 7: published by Paul Straw and last updated
 Revision 8: published by JohnDavid Dalton and last updated
 Revision 9: published by Fabrizio and last updated
 Revision 10: published by runTarm
 Revision 11: published
 Revision 12: published
 Revision 13: published by Steffen Haugk
 Revision 14: published
 Revision 15: published
 Revision 16: published
 Revision 17: published
 Revision 18: published
 Revision 19: published
 Revision 20: published by Simon
 Revision 21: published by Sam
 Revision 22: published
 Revision 23: published by Michael Programs
 Revision 24: published
 Revision 25: published
 Revision 26: published by Yar
 Revision 27: published
 Revision 28: published by Yar
 Revision 30: published by dested
 Revision 31: published
 Revision 32: published
 Revision 33: published
 Revision 34: published
 Revision 35: published
 Revision 36: published
 Revision 37: published
 Revision 38: published
 Revision 39: published
 Revision 41: published
 Revision 42: published by Marco Pfeiffer
 Revision 44: published
 Revision 45: published by JonCarlos Rivera
 Revision 46: published by JonCarlos Rivera
 Revision 47: published by Philip Peterson
 Revision 48: published
 Revision 50: published
 Revision 51: published by JonCarlos Rivera
 Revision 52: published by JonCarlos Rivera
 Revision 53: published
 Revision 55: published
 Revision 56: published
 Revision 57: published by azazdeaz
 Revision 58: published by azazdeaz
 Revision 59: published
 Revision 60: published
 Revision 62: published
 Revision 63: published by Eric Teubert
 Revision 64: published
 Revision 66: published
 Revision 67: published
 Revision 68: published
 Revision 69: published
 Revision 70: published
 Revision 71: published
 Revision 72: published
 Revision 74: published
 Revision 75: published
 Revision 76: published by Devraj Mehta
 Revision 77: published
 Revision 79: published
 Revision 80: published
 Revision 81: published
 Revision 82: published
 Revision 83: published
 Revision 85: published by atSetKey
 Revision 86: published by Yaakov
 Revision 87: published by imma
 Revision 88: published
 Revision 89: published by techmatt
 Revision 90: published by maurizzzio
 Revision 91: published
 Revision 92: published by ly tran
 Revision 93: published
 Revision 94: published
 Revision 95: published
 Revision 96: published
 Revision 97: published
 Revision 98: published
 Revision 99: published
 Revision 100: published
 Revision 101: published by gfx
 Revision 103: published by Rob Adams
 Revision 105: published
 Revision 106: published
 Revision 107: published
 Revision 108: published
 Revision 109: published
 Revision 110: published by Rohit Vighne
 Revision 111: published by ChenPang He
 Revision 112: published by jdiaz5513
 Revision 114: published
 Revision 115: published by Aicke Schulz
 Revision 116: published
 Revision 117: published by Shane BrinkmanDavis
 Revision 118: published
 Revision 120: published
 Revision 121: published
 Revision 122: published
 Revision 123: published
 Revision 124: published
 Revision 125: published
 Revision 126: published by PAEz
 Revision 129: published
 Revision 130: published by nordligulv
 Revision 131: published
 Revision 132: published
 Revision 133: published
0 comments