Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Date Resolver Number Converter vs Cascading Ternary
(version: 1)
Comparing performance of:
Number converter vs Cascading ternary
Created:
5 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const count = new Array(1000000); const epoch = new Date(0); const dateArray = count.map((i) => new Date(i)); const numberArray = count.map((i) => new Date(i).getTime()); const stringArray = count.map((i) => new Date(i).toISOString()); const undefinedArray = count.map((i) => undefined); const mixedArray = count.map((i) => { const options = [dateArray, numberArray, stringArray, undefinedArray]; return dateArray[Math.floor(Math.random() * 4)][i]; });
Tests:
Number converter
function dateResolver( value ) { return Number(value ?? 0) || new Date(value).getTime(); } let date; dateArray.forEach((value) => { date = dateResolver(value); }); numberArray.forEach((value) => { date = dateResolver(value); }); stringArray.forEach((value) => { date = dateResolver(value); }); undefinedArray.forEach((value) => { date = dateResolver(value); }); mixedArray.forEach((value) => { date = dateResolver(value); });
Cascading ternary
function dateResolver( value ) { return value === undefined ? 0 : Number.isInteger(value) ? value : value instanceof Date ? value.getTime() : new Date(value).getTime(); } let date; dateArray.forEach((value) => { date = dateResolver(value); }); numberArray.forEach((value) => { date = dateResolver(value); }); stringArray.forEach((value) => { date = dateResolver(value); }); undefinedArray.forEach((value) => { date = dateResolver(value); }); mixedArray.forEach((value) => { date = dateResolver(value); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Number converter
Cascading ternary
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15
Browser/OS:
Safari 26 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Number converter
16.9 Ops/sec
Cascading ternary
16.7 Ops/sec
Related benchmarks:
toISOString and literalISO 2
toISOString and literalISO 3
fight to the death - for loop vs chained array methods (100,000)
fight to the death - for loop vs chained methods1
fight to the death - for loop vs chained methods1 array length 100
fight to the death - for loop vs chained methods 10,000
fight to the death - for loop vs chained arr (10)
fight to the death - for loop vs chained arr (100)
Array Apply vs Array Spread
Array Apply vs Array Spread vs Array Fill
Comments
Confirm delete:
Do you really want to delete benchmark?