Reputation: 6003
What's the fastest way to check a blank string?
[string eq $s ""]
[string compare $s ""]
[expr $s == ""]
[regexp ^$ $s]
Upvotes: 1
Views: 1931
Reputation: 137567
I'd expect that either:
string equal $s ""
or
expr {$s eq ""}
would be fastest; the two cases will generate virtually identical bytecode so I wouldn't expect to distinguish them.
Upvotes: 2
Reputation: 16428
proc check {} {
set s {}
puts "string equal ->[time {string eq $s ""} 100000]"
puts "string compare ->[time {string compare $s ""} 100000]"
puts "regexp ->[time {regexp ^$ $s} 100000]"
puts "expr == ->[time {expr {$s == ""}} 100000]"
puts "expr eq ->[time {expr {$s eq ""}} 100000]"
}
check ; # See the behavior in your PC
Upvotes: 2