Float to Int conversion comparison

JavaScript performance comparison

Revision 42 of this test case created by Abdellah

Preparation code

<script>
// fill array with random decimal values
var testNumbers = [], resultNumbers = [];
var num = 1000;
var multiplier = 10;
for (var i = 0; i < num; i++) {
    if (i % 50 === 0) {
        multiplier *= 10;
    }
    testNumbers[i] = Math.random() * multiplier;
    resultNumbers[i] = 0;
}
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Math.trunc
for (var i = 0; i < testNumbers.length; i++) {
    resultNumbers[i] = Math.trunc(testNumbers[i]);
}
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments