-
-
Notifications
You must be signed in to change notification settings - Fork 482
/
Copy pathbenchmark.sh
62 lines (52 loc) · 1.24 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
#!/bin/bash
mkdir benchmark.$$.tmp
cd benchmark.$$.tmp
(
set -e
echo Setting up...
dirnames=`echo {0..9}/{0..9}/{0..9}/{0..9}` # 10000 dirs
filenames=`echo {0..9}/{0..9}/{0..9}/{0..9}/{0..9}.txt`
echo $dirnames | xargs mkdir -p
echo $filenames | xargs touch
echo
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("../");
console.log(glob.sync("**/*.txt").length);'
echo
echo Node glob async timing:
time node -e '
var glob=require("../");
glob("**/*.txt", function (er, files) {
console.log(files.length)
})'
echo
)
cd ..
rm -rf benchmark.$$.tmp