Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
empty string 3
Different ways of checking if string is empty
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
not string
176279360.0 Ops/sec
length is 0
171709408.0 Ops/sec
not length
160182704.0 Ops/sec
string equals empty string
157284720.0 Ops/sec
Tests:
not string
function isEmpty(string) { return !string; } const text = 'This is an example of a non empty string'; const empty = ''; const test1 = isEmpty(text); const test2 = isEmpty(empty);
length is 0
function isEmpty(string) { return string.length === 0; } const text = 'This is an example of a non empty string'; const empty = ''; const test1 = isEmpty(text); const test2 = isEmpty(empty);
not length
function isEmpty(string) { return !string.length; } const text = 'This is an example of a non empty string'; const empty = ''; const test1 = isEmpty(text); const test2 = isEmpty(empty);
string equals empty string
function isEmpty(string) { return string.length > 0; } const text = 'This is an example of a non empty string'; const empty = ''; const test1 = isEmpty(text); const test2 = isEmpty(empty);