forked from isaacs/node-glob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.sh
57 lines (48 loc) · 1.05 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
#!/bin/bash
export CDPATH=
tmp=${TMPDIR:-/tmp}
bash make-benchmark-fixture.sh
wd=$PWD
cd $tmp/benchmark-fixture
set -e
if [[ "`bash --version`" =~ version\ 4 ]]; then
echo Bash timing:
time bash -c 'shopt -s globstar; echo **/*.txt | wc -w'
fi
echo
if type zsh; then
echo Zsh timing:
time zsh -c 'echo **/*.txt | wc -w'
fi
echo
echo Node statSync and readdirSync timing:
time node -e '
var fs=require("fs");
var count = 0;
function walk (path) {
if (path.slice(-4) === ".txt") count++;
var stat = fs.statSync(path);
if (stat.isDirectory()) {
fs.readdirSync(path).forEach(function(entry) {
walk(path + "/" + entry);
})
}
}
walk(".");
console.log(count)'
echo
echo Node glob.sync timing:
time node -e '
var glob=require(process.argv[1]);
console.log(glob.sync("**/*.txt").length);' "$wd"
echo
echo Node glob async timing:
time node -e '
var glob=require(process.argv[1]);
glob("**/*.txt", function (er, files) {
console.log(files.length)
})' "$wd"
echo
echo Node glob with --prof
cd $wd
bash prof.sh