Advertisement
teknoraver

strlen.sh

Dec 17th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.57 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. string="abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
  4. loops=10000000
  5.  
  6. echo 'empty loop'
  7. i=0
  8. start=$(date +%s)
  9. while [ $i -lt $loops ]; do
  10.     :
  11.     i=$((i+1))
  12. done
  13. echo "took $(($(date +%s) - start))s"
  14.  
  15. echo 'checking with = ""'
  16. i=0
  17. start=$(date +%s)
  18. while [ $i -lt $loops ]; do
  19.     [ "$string" = "" ]
  20.     i=$((i+1))
  21. done
  22. echo "took $(($(date +%s) - start))s"
  23.  
  24. echo 'checking with = ${#} -ne 0'
  25. i=0
  26. start=$(date +%s)
  27. while [ $i -lt $loops ]; do
  28.     [ ${#string} -eq 0 ]
  29.     i=$((i+1))
  30. done
  31. echo "took $(($(date +%s) - start))s"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement