Redirection from file was about 10X+ times faster than using cat and this was done with my heavily loaded bash environmet which makes $() not su efficient.
#!/usr/bin/env bash
file = /tmp/hi
cat_file (){
cat ${file :? } >&2
}
redirect_file (){
contents = "$( < "${ file :? }")"
echo "${ contents :? }" >&2
}
main () {
echo .log "Wrote to file [${ file :? }]"
date > ${file :? }
benchmark 100 cat_file
benchmark 100 redirect_file
}
main "${ @ }"
Benchmarker finished for [cat_file] args=[]
Metric (millis) (millis) Min 1 0.645 P50 (Median) 1 1.233 P90 1 1.474 P95 2 1.589 P99 2 1.856 Max 2 2.075 Total 118 117.724 Iterations 100
Benchmarker finished for [redirect_file] args=[]
Metric (micros) (millis) Min 31 0.031 P50 (Median) 32 0.032 P90 34 0.034 P95 38 0.038 P99 49 0.049 Max 97 0.097 Total 3,350 3.350 Iterations 100