Advertisement
teknoraver

sh strlen test

Jun 17th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.78 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. iterations=100
  4.  
  5. echo 'generating long string...'
  6. long=$(hexdump -n100000 -e '"%x"' /dev/urandom)
  7.  
  8. echo 'doing != and = unquoted ...'
  9. time sh <<EOF
  10. l='$long'
  11. for i in \$(seq 1 $iterations); do [ \$l != '' -o \$l = '' ]; done
  12. EOF
  13.  
  14. echo 'doing != and = "quoted" ...'
  15. time sh <<EOF
  16. l='$long'
  17. for i in \$(seq 1 $iterations); do [ "\$l" != '' -o "\$l" = '' ]; done
  18. EOF
  19.  
  20. echo 'doing -z and -n...'
  21. time sh <<EOF
  22. l='$long'
  23. for i in \$(seq 1 $iterations); do [ -z "\$l" -o -n "\$l" ]; done
  24. EOF
  25.  
  26. echo 'doing double test [ -n ] || [ -z ] ...'
  27. time sh <<EOF
  28. l='$long'
  29. for i in \$(seq 1 $iterations); do [ -n "\$l" ] || [ -z "\$l" ]; done
  30. EOF
  31.  
  32. echo 'doing ${#}'
  33. time sh <<EOF
  34. l='$long'
  35. for i in \$(seq 1 $iterations); do [ \${#l} -ne 0 -o \${#l} -eq 0 ]; done
  36. EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement