Forum Discussion
Kevin_Stewart
Sep 09, 2013Employee
Indeed:
% set num1 "123-456-7890"
% time { regsub -all {\D} $num1 "" } 10000
3.172 microseconds per iteration
% time { string map {"." "" " " "" "-" "" "(" "" ")" ""} $num1 } 10000
1.1674 microseconds per iteration
So then it's really a trade-off between speed and flexibility. Regex will catch more anomalies (ie. "123foo456bar7890") at the expense of CPU time. That said, the goal here was convert a string during access policy evaluation, which should only happen once per session.