1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Test how long it takes to read many files
|
4 |
|
5 | big-stream() {
|
6 | cat */*.py
|
7 | # Python messes up here!
|
8 | #*/*/*.py
|
9 | }
|
10 |
|
11 | py3-count() {
|
12 | echo '=== python3'
|
13 |
|
14 | # Buffered I/O is much faster
|
15 | time big-stream | python3 -c '
|
16 | import sys
|
17 | i = 0
|
18 | for line in sys.stdin:
|
19 | i += 1
|
20 | print(i)
|
21 | '
|
22 | }
|
23 |
|
24 | awk-count() {
|
25 | echo '=== awk'
|
26 | time big-stream | awk '{ i += 1 } END { print i } '
|
27 | }
|
28 |
|
29 | ysh-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 '
|
37 | var i = 0
|
38 | for _ in <> {
|
39 | setvar i += 1
|
40 | }
|
41 | echo $i
|
42 | '
|
43 | }
|
44 |
|
45 | compare() {
|
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 '
|
62 | i=0
|
63 | while read -r line; do
|
64 | i=$(( i + 1 ))
|
65 | done
|
66 | echo $i
|
67 | '
|
68 | echo
|
69 | done
|
70 | }
|
71 |
|
72 | "$@"
|
73 |
|