Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
CUSTOM1 MomentJS vs Native Date
(version: 1)
Comparing performance of:
Moment vs Native
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.0/moment.min.js'></script>
Tests:
Moment
moment('2017-09-29T11:23:40.483Z').add('MMM DD, YYYY hh:mm:ss A');
Native
let a = (date, format) => { const dateObj = typeof date === "string" || typeof date === "number" ? new Date(date) : date if (isNaN(dateObj.getTime())) { return "Invalid Date" } const day = dateObj.getDate() const month = dateObj.getMonth() + 1 const year = dateObj.getFullYear() let hours = dateObj.getHours() // Important: make hours mutable const minutes = dateObj.getMinutes() const seconds = dateObj.getSeconds() let ampm = hours >= 12 ? "PM" : "AM" // Calculate AM/PM // Convert 24-hour to 12-hour format if (format.includes("hh") || format.includes("h")) { hours = hours % 12 hours = hours ? hours : 12 // the hour '0' should be '12' } const replacements = { YYYY: String(year), YY: String(year).slice(-2), MM: String(month).padStart(2, "0"), M: String(month), DD: String(day).padStart(2, "0"), D: String(day), HH: String(hours).padStart(2, "0"), H: String(hours), hh: String(hours).padStart(2, "0"), // 12-hour format with leading zero h: String(hours), // 12-hour format without leading zero mm: String(minutes).padStart(2, "0"), m: String(minutes), ss: String(seconds).padStart(2, "0"), s: String(seconds), a: ampm.toLowerCase(), A: ampm } let formattedDate = format for (const [key, value] of Object.entries(replacements)) { formattedDate = formattedDate.replace(new RegExp(key, "g"), value) } return formattedDate } a('2017-09-29T11:23:40.483Z', 'MMM DD, YYYY hh:mm:ss A')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Moment
Native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Moment
115670.8 Ops/sec
Native
221018.3 Ops/sec
Related benchmarks:
new Date vs date.parse
Date vs moment 1238uu
MomentJS vs Native Date
MomentJS vs Native ISO String Fixed Date
date-fns vs moment
MomentJS vs Native Date 2
Moment.js string vs Date in constructor
moment(string) vs moment(new Date(string)) vs new Date(string)
CUSTOM MomentJS vs Native Date
Comments
Confirm delete:
Do you really want to delete benchmark?