Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Fastest way to detect an empty string - better test cases
testing removing beginning and end whitespace vs trim
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/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
regex
5604553.5 Ops/sec
trim
9394265.0 Ops/sec
trimStart
10001834.0 Ops/sec
trimEnd
8820145.0 Ops/sec
Script Preparation code:
var strings = [' ', ' a', 'a ', ' a '];
Tests:
regex
strings.filter(s=>/^\s+$/.test(s));
trim
strings.filter(s=>!s.trim())
trimStart
strings.filter(s=>s.trimStart())
trimEnd
strings.filter(s=>s.trimEnd())