Reputation: 3103
Say I have in Tcl, a proc name foo, in the main namespace.
I then create a namespace bar, and in it, I call proc foo. Now, since there is no foo::bar proc, the global one will be called. However, I can also explicitly call the global foo by calling ::foo.
Should there be any performance advantage to either of the options? This is not empirical question, but more of an understanding how the proc lookup table should work
Upvotes: 0
Views: 80
Reputation: 137637
Tcl caches these sorts of lookups pretty extensively, so predicting exactly what is going on with performance in the abstract is awkward. Instead, it is better to test! This is done on my laptop with Tcl 8.6…
% proc foo {} {expr 123}
% time { foo } 100000
0.36416123 microseconds per iteration
% namespace eval bar { time { foo } 100000 }
0.36913464 microseconds per iteration
% namespace eval bar { time { ::foo } 100000 }
0.36198978000000004 microseconds per iteration
In short, in this particular test we see that the difference between the calls in terms of speed is down in the noise; I would not trust the difference above.
I suggest writing clear code and not worrying about speed unless you measure a problem.
Upvotes: 2