Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greymd/4548a30365cea2d44f33 to your computer and use it in GitHub Desktop.
Save greymd/4548a30365cea2d44f33 to your computer and use it in GitHub Desktop.
因数分解→因数を全て足し算の速度比較 while vs awk
#bashのwhile readを利用。
$ time seq 1000 | factor | while read a b; do echo $b | tr ' ' '+' | bc ;done > /dev/null
real 0m2.150s
user 0m1.370s
sys 0m3.259s
#awkのfor文を利用
$ time seq 1000 | factor | awk '{s=0;for(i=2;i<=NF;i++){s+=$i}print s;}' > /dev/null
real 0m0.009s
user 0m0.013s
sys 0m0.003s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment