fork(1) download
  1. #!/bin/bash
  2.  
  3. cdIs_num() {
  4. local re='^[+-]?[0-9]+([.][0-9]+)?$';
  5. [[ $1 =~ $re ]]
  6. }
  7.  
  8. is_num() {
  9. local chk=${1#[+-]};
  10. chk=${chk/.}
  11. [ "$chk" ] && [ -z "${chk//[0-9]}" ]
  12. }
  13.  
  14. casenum () {
  15. case ${1#[-+]} in
  16. '' | *[!0-9.]* | *.*.*) return 1;;
  17. *) return 0;;
  18. esac
  19. }
  20.  
  21. for fun in is_num cdIs_num casenum; do
  22. echo "** $fun **" >&2
  23. time for i in {1..10000};do "$fun" +3.14159265; done
  24. done
Success #stdin #stdout #stderr 1.13s 6808KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
** is_num **

real	0m0.326s
user	0m0.321s
sys	0m0.004s
** cdIs_num **

real	0m0.656s
user	0m0.629s
sys	0m0.000s
** casenum **

real	0m0.168s
user	0m0.167s
sys	0m0.000s