$ du -sbh ./input.txt;
# 209M ./input.txt
$ ./benchmark.sh ./input.txt;
Benchmark 1: tr -s \n
Time (mean ± σ): 852.3 ms ± 9.8 ms [User: 823.6 ms, System: 28.4 ms]
Range (min … max): 841.4 ms … 871.8 ms 10 runs
Benchmark 2: grep -vx ''
Time (mean ± σ): 564.1 µs ± 35.2 µs [User: 306.6 µs, System: 221.7 µs]
Range (min … max): 490.5 µs … 1008.2 µs 4622 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark 3: grep -v '^$'
Time (mean ± σ): 566.3 µs ± 34.5 µs [User: 308.2 µs, System: 221.7 µs]
Range (min … max): 499.9 µs … 949.6 µs 5425 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark 4: sed '/^$/d'
Time (mean ± σ): 2.438 s ± 0.008 s [User: 2.394 s, System: 0.043 s]
Range (min … max): 2.427 s … 2.455 s 10 runs
Benchmark 5: awk NF
Time (mean ± σ): 4.090 s ± 0.031 s [User: 4.048 s, System: 0.041 s]
Range (min … max): 4.062 s … 4.152 s 10 runs
Summary
grep -vx '' ran
1.00 ± 0.09 times faster than grep -v '^$'
1510.85 ± 95.89 times faster than tr -s \n
4321.33 ± 270.15 times faster than sed '/^$/d'
7250.52 ± 455.97 times faster than awk NF