* "Donal K. Fellows" <
donal.k...@manchester.ac.uk>
| On 06/07/2017 17:12,
jda...@gmail.com wrote:
| > A faster test for "can this object be a number" would clearly speed
| > up this function, and might be more generally useful. I'm going to
| > look through tcl::unsupported::*, and the internals to see what is
| > available.
>
| The operation we've got is [string is double -strict], which is public
| but perhaps a little non-obvious. That compiles to efficient bytecode.
proc dexpr {val} { catch {expr {double($val)}} }
proc sexpr {val} { string is double -strict $val }
For numbers the difference is small:
% time {dexpr 1.0} 10000000
0.3145418 microseconds per iteration
% time {dexpr 1.0} 10000000
0.3133542 microseconds per iteration
% time {sexpr 1.0} 10000000
0.3403064 microseconds per iteration
% time {sexpr 1.0} 10000000
0.3283447 microseconds per iteration
For non-numbers the difference is huge in favor of 'string is'
% time {dexpr foo} 10000000
2.3977025 microseconds per iteration
% time {dexpr foo} 1000000
2.508554 microseconds per iteration
% time {sexpr foo} 10000000
0.359159 microseconds per iteration
% time {sexpr foo} 10000000
0.3626173 microseconds per iteration
but since a non-number would only raise an error this will probably not
speed up the original problem...
R'