Month Number Speed Test
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
function getMonthString( month) {
return "JanFebMarAprMayJunJulAugSepOctNovDec".indexOf(month) / 3 + 1;
}
function getMonthDate(mon){
return new Date(Date.parse(mon +" 1, 2012")).getMonth()+1
}
var _months = {
"Jan" : "01",
"Feb" : "02",
"Mar" : "03",
"Apr" : "04",
"May" : "05",
"Jun" : "06",
"Jul" : "07",
"Aug" : "08",
"Sep" : "09",
"Oct" : "10",
"Nov" : "11",
"Dec" : "12"
};
function getMonthObject(month) {
return _months[month];
}
function getMonthArray(month)
{
var idx = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'].indexOf(month) + 1;
return idx < 10 ? '0' + idx : idx;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Array Index |
|
pending… |
Object |
|
pending… |
IndexOf String |
|
pending… |
Date parse |
|
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 epascarello
0 comments