Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
most tests 2
(version: 0)
Comparing performance of:
split vs substring vs loop vs charAt vs slice vs number
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var year = '2004 ';
Tests:
split
console.log(year.split(' ')[0]);
substring
console.log(year.substring(0,4))
loop
let substr = "" for (var i = 0; i < 4; i++) { substr += year.charAt(i) } console.log(substr)
charAt
console.log(year.charAt(0) + year.charAt(1) + year.charAt(2) + year.charAt(3))
slice
console.log(year.slice(0, 4));
number
console.log(Number(year));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
split
substring
loop
charAt
slice
number
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Date.toLocaleDateString
Date.toLocaleDateString
Date.parse vs new Date with comparison
Date comparison
Date object vs Number comparison
Comments
Confirm delete:
Do you really want to delete benchmark?