Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
MomentJS VS Date VS Date-Fns - getTtlFromKey #4
(version: 1)
Comparing performance of:
MomentJS vs Date JS vs Date-Fns
Created:
9 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/moment@2.29.4/moment.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/date-fns/cdn.min.js"></script>
Script Preparation code:
function parseDateAsUtc(dateString) { const formatTime = time => { if (!time) return '00'; if (time.length === 1) return `${time}0`; return time; }; const [datePart, timePart] = dateString.split('T'); const parts = timePart.split(':'); const hours = formatTime(parts[0]); const minutes = formatTime(parts[1]); const seconds = formatTime(parts[2]); return new Date(`${datePart}T${hours}:${minutes}:${seconds}.000Z`); };
Tests:
MomentJS
const cacheDurationMinutes = 60; const defaultTtl = cacheDurationMinutes * 60; const effectiveDate = '2025-07-18T18'; const now = moment.utc(); const keyEffectiveDateStart = moment.utc(effectiveDate); const keyEffectiveDateEnd = keyEffectiveDateStart.clone() .add(cacheDurationMinutes, 'minutes'); const secondsTillKeyEnd = keyEffectiveDateEnd.diff(now, 'seconds'); const result = Math.min(defaultTtl, Math.max(0, secondsTillKeyEnd)) || defaultTtl;
Date JS
const cacheDurationMinutes = 60; const defaultTtl = cacheDurationMinutes * 60; const effectiveDate = '2025-07-18T18'; const now = new Date(); const keyEffectiveDateStart = parseDateAsUtc(effectiveDate); const keyEffectiveDateEnd = new Date(keyEffectiveDateStart.getTime()); //keyEffectiveDateEnd.setUTCMinutes(keyEffectiveDateEnd.getUTCMinutes() + cacheDurationMinutes); const millisecondsInMinute = 60000; keyEffectiveDateEnd.setTime(keyEffectiveDateEnd.getTime() + cacheDurationMinutes * millisecondsInMinute); const secondsTillKeyEnd = (keyEffectiveDateEnd.getTime() - now.getTime()) / 1000; const result = Math.min(defaultTtl, Math.max(0, secondsTillKeyEnd)) || defaultTtl;
Date-Fns
const cacheDurationMinutes = 60; const defaultTtl = cacheDurationMinutes * 60; const effectiveDate = '2025-07-18T18'; const now = new Date(); const keyEffectiveDateStart = parseDateAsUtc(effectiveDate); const keyEffectiveDateEnd = dateFns.addMinutes(keyEffectiveDateStart, cacheDurationMinutes); const secondsTillKeyEnd = dateFns.differenceInSeconds(keyEffectiveDateEnd, now); const result = Math.min(defaultTtl, Math.max(0, secondsTillKeyEnd)) || defaultTtl;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
MomentJS
Date JS
Date-Fns
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
MomentJS
120622.9 Ops/sec
Date JS
1524643.4 Ops/sec
Date-Fns
1014559.8 Ops/sec
Related benchmarks:
Moment Parse vs JS Manual Parse
Moment Tests timestamp
Moment Tests timestamp 2
CUSTOM1 MomentJS vs Native Date
MomentJS VS Date
MomentJS VS Date VS Date-Fns - getRoundedDate
MomentJS VS Date VS Date-Fns - getRoundedDate #2
Date JS VS Date-Fns - differenceInSeconds
Date JS VS Date-Fns VS MomentJS - differenceInSeconds
Comments
Confirm delete:
Do you really want to delete benchmark?