Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
match vs test vs split vs trim to check for empty string or all spaces
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
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 Edg/131.0.0.0
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
match
1487905.2 Ops/sec
test
1631909.6 Ops/sec
split
1415003.8 Ops/sec
trim
2661871.2 Ops/sec
Script Preparation code:
window.strs = [[' ', true], ['', true], ['asdf', false], [' ', true]]
Tests:
match
window.strs.forEach(([str, expected]) => { (str.match(/^ *$/) !== null) === expected; });
test
window.strs.forEach(([str, expected]) => { /^ *$/.test(str) === expected; });
split
window.strs.forEach(([str, expected]) => { (str.split(/^ *$/).length === 2) === expected; });
trim
window.strs.forEach(([str, expected]) => { (str.trim().length === 0) === expected; });