ValidarTime
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
function ValidarTime(wcolObrig, valor, obrig) {
if (obrig == "OBRIG") {
if (wcolObrig == "S" && valor == "") return "- é de preenchimento obrigatório"
}
if (valor == "") return ""
var i=valor.indexOf(":")
if (i != 2) return " - hora inválida"
var hh=valor.substr(0,2)
var mm=valor.substr(3)
if ((hh == " " || hh == "__" || hh == "") && (mm == " " || mm == "__" || mm == "")) {
if (obrig == "OBRIG" && wcolObrig == "S") {
return "- é de preenchimento obrigatório"
} else {
return ""
}
}
if ("0123456789".indexOf(hh.substr(0,1)) == -1 || "0123456789".indexOf(hh.substr(1,1)) == -1 || "0123456789".indexOf(mm.substr(0,1)) == -1 || "0123456789".indexOf(mm.substr(1,1)) == -1) return " - hora inválida"
var hhv=parseInt(hh)
var mmv=parseInt(mm)
if (isNaN(hhv) || isNaN(mmv)) return " - hora inválida"
if (hhv < 0 || hhv > 23 || mmv < 0 || mmv > 59) return " - hora inválida"
return ""
}
function ValidarTime2(wcolObrig, valor, obrig) {
if(valor==""){
if (obrig == "OBRIG" && wcolObrig == "S") {
return "- é de preenchimento obrigatório"
} else {
return ""
}
}
if( !/^\d{2}:\d{2}$/i.test(valor)) {
return " - hora inválida";
}
return ""
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
ValidarTime |
|
pending… |
ValidarTime2 |
|
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 terslak
- Revision 2: published
0 comments