タグ

ブックマーク / futuremix.org (1)

  • bash ループ中のリダイレクトはまとめた方が高速になる

    bash の出力をファイルに行なう際、ループ中で毎回 echo のたびにリダイレクトをすると遅いのではないかと思い検証してみた。 #! /bin/bash - ## test1.sh echo '' > output1.dat for i in {0..99999} do echo $i >> output1.dat done $ time ./test1.sh real 0m3.003s user 0m2.364s sys 0m0.638s これをループのブロックごとリダイレクトさせると高速になる。 #! /bin/bash - ## test2.sh for i in {0..99999} do echo $i done > output2.dat $ time ./test2.sh real 0m0.841s user 0m0.537s sys 0m0.305s ちなみにブロックごと

    oopsops
    oopsops 2013/01/10
  • 1