-
-
Notifications
You must be signed in to change notification settings - Fork 482
/
benchmark.sh
180 lines (151 loc) · 5.3 KB
/
benchmark.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
export CDPATH=
set -e
. patterns.sh
bash make-benchmark-fixture.sh
wd=$PWD
mkdir -p "$wd/bench-working-dir/fixture"
cd "$wd/bench-working-dir"
cat > "$wd/bench-working-dir/package.json" <<PJ
{
"dependencies": {
"fast-glob": "3",
"glob7": "npm:glob@7",
"glob8": "npm:glob@8",
"globby": "13"
}
}
PJ
if ! [ -d "$wd/bench-working-dir/node_modules/glob7" ] || \
! [ -d "$wd/bench-working-dir/node_modules/glob8" ] || \
! [ -d "$wd/bench-working-dir/node_modules/globby" ]; then
(cd "$wd/bench-working-dir" &>/dev/null; npm i --silent)
fi
tt () {
time "$@"
}
t () {
rm -f stderr stdout
tt "$@" 2>stderr >stdout || (cat stderr >&2 ; exit 1 )
echo $(cat stderr | grep real | awk -F $'\t' '{ print $2 }' || true)' '\
$(cat stdout)
# rm -f stderr stdout
}
# warm up the fs cache so we don't get a spurious slow first result
bash -c 'for i in **; do :; done'
for p in "${patterns[@]}"; do
echo
echo "--- pattern: '$p' ---"
# if [[ "`bash --version`" =~ version\ 4 ]] || [[ "`bash --version`" =~ version\ 5 ]]; then
# echo -n $'bash \t'
# t bash -c 'shopt -s globstar; echo '"$p"' | wc -w'
# fi
# if type zsh &>/dev/null; then
# echo -n $'zsh \t'
# t zsh -c 'echo '"$p"' | wc -w'
# fi
# echo -n $'node glob v7 sync \t'
# t node -e '
# var glob=require(process.argv[1])
# console.log(glob.sync(process.argv[2]).length)
# ' "$wd/bench-working-dir/node_modules/glob7" "$p"
# echo -n $'node glob v7 async \t'
# t node -e '
# var glob=require(process.argv[1])
# glob(process.argv[2], (er, files) => {
# console.log(files.length)
# })' "$wd/bench-working-dir/node_modules/glob7" "$p"
echo '~~ sync ~~'
echo -n $'node fast-glob sync \t'
cat > "$wd"/bench-working-dir/fast-glob-sync.cjs <<CJS
const fg = require('fast-glob')
console.log(fg.sync([process.argv[2]]).length)
CJS
t node "$wd/bench-working-dir/fast-glob-sync.cjs" "$p"
echo -n $'node globby sync \t'
cat > "$wd"/bench-working-dir/globby-sync.mjs <<MJS
import { globbySync } from "globby"
console.log(globbySync([process.argv[2]]).length)
MJS
t node "$wd/bench-working-dir/globby-sync.mjs" "$p"
# echo -n $'node current globSync cjs \t'
# cat > "$wd/bench-working-dir/sync.cjs" <<CJS
# const {globSync} = require("$wd/dist/cjs/index-cjs.js")
# console.log(globSync(process.argv[2]).length)
#CJS
# t node "$wd/bench-working-dir/sync.cjs" "$p"
#
# echo -n $'node current glob async cjs \t'
# cat > "$wd/bench-working-dir/async.cjs" <<CJS
# const glob = require("$wd/dist/cjs/index-cjs.js")
# glob(process.argv[2]).then(files => console.log(files.length))
#CJS
# t node "$wd/bench-working-dir/async.cjs" "$p"
# echo -n $'node glob v8 sync \t'
# cat > "$wd/bench-working-dir/glob-8-sync.cjs" <<CJS
# var glob=require('glob8')
# console.log(glob.sync(process.argv[2]).length)
# CJS
# t node "$wd/bench-working-dir/glob-8-sync.cjs" "$p"
echo -n $'node current globSync mjs \t'
cat > "$wd/bench-working-dir/sync.mjs" <<MJS
import {globSync} from '$wd/dist/mjs/index.js'
console.log(globSync(process.argv[2]).length)
MJS
t node "$wd/bench-working-dir/sync.mjs" "$p"
echo -n $'node current glob syncStream \t'
cat > "$wd/bench-working-dir/stream-sync.mjs" <<MJS
import {globStreamSync} from '$wd/dist/mjs/index.js'
let c = 0
globStreamSync(process.argv[2])
.on('data', () => c++)
.on('end', () => console.log(c))
MJS
t node "$wd/bench-working-dir/stream-sync.mjs" "$p"
echo '~~ async ~~'
echo -n $'node fast-glob async \t'
cat > "$wd"/bench-working-dir/fast-glob-async.cjs <<CJS
const fg = require('fast-glob')
fg([process.argv[2]]).then(r => console.log(r.length))
CJS
t node "$wd/bench-working-dir/fast-glob-async.cjs" "$p"
echo -n $'node globby async \t'
cat > "$wd"/bench-working-dir/globby-async.mjs <<MJS
import { globby } from "globby"
globby([process.argv[2]]).then((files) => {
console.log(files.length)
})
MJS
t node "$wd/bench-working-dir/globby-async.mjs" "$p"
# echo -n $'node glob v8 async \t'
# cat > "$wd/bench-working-dir/glob-8-async.cjs" <<CJS
# var glob=require('glob8')
# glob(process.argv[2], (er, results) =>
# console.log(results.length)
# )
# CJS
# t node "$wd/bench-working-dir/glob-8-async.cjs" "$p"
echo -n $'node current glob async mjs \t'
cat > "$wd/bench-working-dir/async.mjs" <<MJS
import glob from '$wd/dist/mjs/index.js'
glob(process.argv[2]).then(files => console.log(files.length))
MJS
t node "$wd/bench-working-dir/async.mjs" "$p"
echo -n $'node current glob stream \t'
cat > "$wd/bench-working-dir/stream.mjs" <<MJS
import {globStream} from '$wd/dist/mjs/index.js'
let c = 0
globStream(process.argv[2])
.on('data', () => c++)
.on('end', () => console.log(c))
MJS
t node "$wd/bench-working-dir/stream.mjs" "$p"
# echo -n $'node current glob sync cjs -e \t'
# t node -e '
# console.log(require(process.argv[1]).sync(process.argv[2]).length)
# ' "$wd/dist/cjs/index-cjs.js" "$p"
# echo -n $'node current glob async cjs -e\t'
# t node -e '
# require(process.argv[1])(process.argv[2]).then((files) => console.log(files.length))
# ' "$wd/dist/cjs/index-cjs.js" "$p"
done