$ ./check.sh
array: 10000
real 0m10.606s
user 0m10.470s
sys 0m0.027s
grep: 10000
real 0m29.172s
user 0m17.108s
sys 0m20.906s
array: 20000
real 0m24.255s
user 0m22.790s
sys 0m1.238s
grep: 20000
real 0m57.901s
user 0m33.296s
sys 0m42.242s
array: 40000
real 0m42.233s
user 0m39.909s
sys 0m2.145s
grep: 40000
real 1m36.241s
user 1m0.850s
sys 1m12.033s
###############
return at 1
array: 10000
real 0m1.764s
user 0m1.751s
sys 0m0.009s
grep: 10000
real 0m23.679s
user 0m15.030s
sys 0m17.628s
array: 20000
real 0m3.342s
user 0m3.321s
sys 0m0.018s
grep: 20000
real 0m51.142s
user 0m30.880s
sys 0m38.151s
array: 40000
real 0m7.286s
user 0m7.222s
sys 0m0.044s
grep: 40000
real 1m41.529s
user 1m0.430s
sys 1m16.004s
Linuxでやった場合
Debian 7.6
grep (GNU grep) 2.12
GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
$ ./check.sh
array: 10000
real 0m11.317s
user 0m11.041s
sys 0m0.268s
grep: 10000
real 0m13.048s
user 0m1.072s
sys 0m2.164s
array: 20000
real 0m23.659s
user 0m22.613s
sys 0m1.032s
grep: 20000
real 0m32.762s
user 0m2.216s
sys 0m5.328s
array: 40000
real 0m47.732s
user 0m45.647s
sys 0m2.060s
grep: 40000
real 1m54.354s
user 0m4.100s
sys 0m16.217s
###############
return at 1
array: 10000
real 0m1.921s
user 0m1.908s
sys 0m0.008s
grep: 10000
real 0m33.102s
user 0m1.780s
sys 0m3.960s
array: 20000
real 0m3.847s
user 0m3.816s
sys 0m0.032s
grep: 20000
real 1m6.348s
user 0m2.592s
sys 0m8.433s
array: 40000
real 0m7.708s
user 0m7.708s
sys 0m0.000s
grep: 40000
real 2m14.146s
user 0m7.416s
sys 0m15.985s