Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
simple js test
(version: 1)
Comparing performance of:
expanded script vs Luxon script vs fns
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/luxon@3.5.0/build/global/luxon.min.js"></script> <script src='https://cdn.jsdelivr.net/npm/date-fns@4.1.0/cdn.min.js'></script>
Script Preparation code:
function expanded() { const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero-based const day = String(now.getDate()).padStart(2, '0'); const hours = String(now.getHours()).padStart(2, '0'); const minutes = String(now.getMinutes()).padStart(2, '0'); const seconds = String(now.getSeconds()).padStart(2, '0'); const milliseconds = String(now.getMilliseconds()).padStart(3, '0'); return `${year}-${month}-${day}_${hours}${minutes}${seconds}.${milliseconds}`; } function luxonDT() { const formattedDate = luxon.DateTime.now().toFormat("yyyy-MM-dd_HHmmss.SSS"); return formattedDate; } function padZero(number, length) { return number.toString().padStart(length, '0'); } const MS_PER_SECOND = 1000; const MS_PER_MINUTE = MS_PER_SECOND * 60; const MS_PER_HOUR = MS_PER_MINUTE * 60; const MS_PER_DAY = MS_PER_HOUR * 24; function formatUnixTimestamp() { let timestamp = Date.now(); let totalDays = Math.floor(timestamp / MS_PER_DAY); let remainingMs = timestamp % MS_PER_DAY; // Calculate current time components const hours = Math.floor(remainingMs / MS_PER_HOUR); remainingMs %= MS_PER_HOUR; const minutes = Math.floor(remainingMs / MS_PER_MINUTE); remainingMs %= MS_PER_MINUTE; const seconds = Math.floor(remainingMs / MS_PER_SECOND); const milliseconds = remainingMs % MS_PER_SECOND; // Calculate current year let year = 1970; while (true) { const daysInYear = (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0) ? 366 : 365; if (totalDays >= daysInYear) { totalDays -= daysInYear; year++; } else { break; } } // Days in each month const daysInMonth = [31, (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // Calculate current month let month = 0; while (totalDays >= daysInMonth[month]) { totalDays -= daysInMonth[month]; month++; } month++; // Convert month to 1-based index // Remaining days are the current day const day = totalDays + 1; // Convert day to 1-based index // Helper function to pad numbers with leading zeros const pad = (num, size) => num.toString().padStart(size, '0'); // Format the date string return `${year}-${pad(month, 2)}-${pad(day, 2)}_${pad(hours, 2)}${pad(minutes, 2)}${pad(seconds, 2)}.${pad(milliseconds, 3)}`; }
Tests:
expanded script
expanded();
Luxon script
luxonDT();
fns
formatUnixTimestamp();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
expanded script
Luxon script
fns
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
expanded script
5978571.5 Ops/sec
Luxon script
526876.5 Ops/sec
fns
4255457.0 Ops/sec
Related benchmarks:
days in month
Date with date
epoch milliseconds to ISO string
the battle to he death
fight to the death - for loop vs chained (Dr Vacant - 1,000,000)
rnawklndklasndklsandklsadsa
ewhurtjytitut
rt15r156we1r5wqeq
date formatter libraries vs native
Comments
Confirm delete:
Do you really want to delete benchmark?