shell のチルダと$HOMEのどちらが解決が早いか雑に試したら$HOMEの方が早かった
2017-11-19 Sun.
以下検証結果。文字列に変更が加わっているので参照渡しではないはず……。
tilda.sh
1for i in $(seq 1 1000000); do2 str=~/tmp3done4echo $str
1~/s/g/e/s/shell ❯❯❯ time sh tilda.sh2/Users/yuta/tmp3sh tilda.sh 4.28s user 0.06s system 100% cpu 4.305 total4~/s/g/e/s/shell ❯❯❯ time sh tilda.sh5/Users/yuta/tmp6sh tilda.sh 4.29s user 0.06s system 100% cpu 4.318 total7~/s/g/e/s/shell ❯❯❯ time sh tilda.sh8/Users/yuta/tmp9sh tilda.sh 4.37s user 0.06s system 100% cpu 4.397 total10~/s/g/e/s/shell ❯❯❯ time sh tilda.sh11/Users/yuta/tmp12sh tilda.sh 4.30s user 0.06s system 100% cpu 4.322 total13~/s/g/e/s/shell ❯❯❯ time sh tilda.sh14/Users/yuta/tmp15sh tilda.sh 4.68s user 0.10s system 99% cpu 4.812 total
home.sh
1for i in $(seq 1 1000000); do2 str=$HOME/tmp3done4echo $str
1~/s/g/e/s/shell ❯❯❯ time sh home.sh2/Users/yuta/tmp3sh home.sh 4.23s user 0.06s system 100% cpu 4.252 total4~/s/g/e/s/shell ❯❯❯ time sh home.sh5/Users/yuta/tmp6sh home.sh 4.19s user 0.06s system 100% cpu 4.207 total7~/s/g/e/s/shell ❯❯❯ time sh home.sh8/Users/yuta/tmp9sh home.sh 4.14s user 0.06s system 101% cpu 4.157 total10~/s/g/e/s/shell ❯❯❯ time sh home.sh11/Users/yuta/tmp12sh home.sh 4.28s user 0.06s system 101% cpu 4.303 total13~/s/g/e/s/shell ❯❯❯ time sh home.sh14/Users/yuta/tmp15sh home.sh 4.27s user 0.06s system 100% cpu 4.299 total
Pickup
Under Construction