Last active
August 29, 2015 14:15
-
-
Save greymd/4548a30365cea2d44f33 to your computer and use it in GitHub Desktop.
因数分解→因数を全て足し算の速度比較 while vs awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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