OILS / benchmarks / io / read-lines.sh View on Github | oilshell.org

42 lines, 13 significant
1#!/usr/bin/env bash
2#
3# Test how long it takes to read many files
4
5big-stream() {
6 cat */*.py
7 # Python messes up here!
8 #*/*/*.py
9}
10
11compare() {
12 echo '=== python3'
13
14 # Buffered I/O is much faster
15 time big-stream | python3 -c '
16import sys
17i = 0
18for line in sys.stdin:
19 i += 1
20print(i)
21'
22
23 echo '=== awk'
24 time big-stream | awk '{ i += 1 } END { print i } '
25
26 for sh in dash bash; do
27 echo === $sh
28
29 time big-stream | $sh -c '
30i=0
31while read -r line; do
32 i=$(( i + 1 ))
33done
34echo $i
35'
36 done
37
38
39}
40
41"$@"
42