GetSizeNumber

JavaScript performance comparison

Test case created by terslak

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    //******* devolver valor numérico mesmo que tenha px
    function GetSizeNumber(val) {
        var rval=0
        var wval="" + val
        var ix=wval.indexOf("px")
        if (ix > -1) {
                rval=Number(wval.substr(0,ix))
        } else {
                ix=wval.indexOf("pt")
                if (ix > -1) {
                        rval=Number(wval.substr(0,ix))
                } else {
                        rval=Number(wval)
                        if (isNaN(rval)) rval=0
                }
        }
        return rval
    }
   
    //******* devolver valor numérico mesmo que tenha px
    function GetSizeNumber2(val) {
        return parseInt(val)
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
GetSizeNumber
GetSizeNumber("23px")
GetSizeNumber("23pt")
GetSizeNumber("23")
pending…
GetSizeNumber2
GetSizeNumber2("23px")
GetSizeNumber2("23pt")
GetSizeNumber2("23")
pending…

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

Compare results of other browsers

0 comments

Add a comment