GetSizeNumber
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
GetSizeNumber |
|
pending… |
GetSizeNumber2 |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments