I want to check whether or not a variable string data
contain empty string.
Which is more efficient, data.Length==0
or data==string.Empty
?
I forgot to say, the data
has been checked and it is guaranteed to be not null
.
Test results for 100 million iterations:
Equality operator ==: 796 ms
string.Equals: 811 ms
string.IsNullOrEmpty: 312 ms
Length: 140 ms [fastest]
Instance Equals: 1077 ms
source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With