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

73 lines, 32 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
11py3-count() {
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
24awk-count() {
25 echo '=== awk'
26 time big-stream | awk '{ i += 1 } END { print i } '
27}
28
29ysh-count() {
30 echo '=== ysh'
31
32 local ysh=_bin/cxx-opt/ysh
33 ninja $ysh
34
35 # New buffered read!
36 time big-stream | $ysh -c '
37var i = 0
38for _ in <> {
39 setvar i += 1
40}
41echo $i
42 '
43}
44
45compare() {
46 py3-count
47 echo
48
49 awk-count
50 echo
51
52 ysh-count
53 echo
54
55 local osh=_bin/cxx-opt/osh
56 ninja $osh
57
58 for sh in dash bash $osh; do
59 echo === $sh
60
61 time big-stream | $sh -c '
62i=0
63while read -r line; do
64 i=$(( i + 1 ))
65done
66echo $i
67'
68 echo
69 done
70}
71
72"$@"
73