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 | compare() {
|
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 | 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 '
|
30 | i=0
|
31 | while read -r line; do
|
32 | i=$(( i + 1 ))
|
33 | done
|
34 | echo $i
|
35 | '
|
36 | done
|
37 |
|
38 |
|
39 | }
|
40 |
|
41 | "$@"
|
42 |
|