File: benchmark.sh

package info (click to toggle)
node-glob 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 816 kB
  • ctags: 46
  • sloc: sh: 75; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (4)
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