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
trimEnd
11.6M/s
trimStart
10.9M/s
trim
10.1M/s
regex
5.5M/s
View exact numbers
Test name
Executions per second
✓
trimEnd
11,619,358 Ops/sec
trimStart
10,933,349 Ops/sec
trim
10,098,110 Ops/sec
regex
5,549,701 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())