Double Tilde vs. ParseInt (v16)

Revision 16 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
if ($.browser.msie) {
    var superParseInt = function(a) {
        return ~~a;
    };
} else {
    var superParseInt = function(a) {
        a = parseInt(a, 10);
        a = isNaN(a) ? 0 : a;
    }
}
</script>

Setup

var i = '1561565', j;

Test runner

Ready to run.

Testing in
TestOps/sec
Double Tilde
j = ~~i;
ready
ParseInt
j = parseInt(i, 10);
ready
Plus sign
j = +(i);
ready
Times 1
j = i*1;
ready
Best of both worlds?
j = superParseInt(i);
ready

Revisions

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