Skip to content

Commit

Permalink
Add benchmark/profiling scripts and fixture stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Nov 12, 2014
1 parent f95ff40 commit d9bf761
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 63 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.*.swp
test/a/
node_modules/*
benchmark-fixture
v8.log
profile.txt
111 changes: 52 additions & 59 deletions benchmark.sh
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
#!/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);
})
}
export CDPATH=

bash make-benchmark-fixture.sh
cd 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("../");
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
)

}
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

echo Node glob with --prof
cd ..
rm -rf benchmark.$$.tmp
bash prof.sh
12 changes: 12 additions & 0 deletions make-benchmark-fixture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
export CDPATH=
set -e
if ! [ -d benchmark-fixture ]; then
echo Making benchmark fixtures
mkdir benchmark-fixture
cd benchmark-fixture
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
fi
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
"once": "^1.3.0"
},
"devDependencies": {
"tap": "~0.4.0",
"mkdirp": "0",
"rimraf": "1"
"rimraf": "^2.2.8",
"tap": "~0.4.0",
"tick": "0.0.6"
},
"scripts": {
"test": "tap test/*.js",
"test-regen": "TEST_REGEN=1 node test/00-setup.js"
"prepublish": "npm run benchclean",
"test": "npm run benchclean; tap test/*.js",
"test-regen": "npm run benchclean; TEST_REGEN=1 node test/00-setup.js",
"bench": "bash benchmark.sh",
"prof": "bash prof.sh && cat profile.txt",
"benchclean": "rm -rf benchmark-fixture v8.log profile.txt"
},
"license": "ISC"
}
16 changes: 16 additions & 0 deletions prof.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
export CDPATH=
set -e

bash make-benchmark-fixture.sh
cd benchmark-fixture

node --prof -e '
var glob=require("../");
glob("**/*.txt", function (er, files) {
console.log(files.length)
})
//console.log(glob.sync("**/*.txt").length);
'
mv v8.log ..
node-tick-processor > profile.txt
4 changes: 4 additions & 0 deletions test/bash-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"./node_modules/once",
"./node_modules/rimraf",
"./node_modules/tap",
"./node_modules/tick",
"./test/00-setup.js",
"./test/a",
"./test/bash-comparison.js",
Expand Down Expand Up @@ -123,12 +124,15 @@
"/tmp/glob-test/quux",
"/tmp/glob-test/qwer",
"/tmp/glob-test/rewq",
"benchmark.sh",
"examples",
"glob.js",
"LICENSE",
"make-benchmark-fixture.sh",
"node_modules",
"oh-my-glob.gif",
"package.json",
"prof.sh",
"README.md",
"test"
],
Expand Down

0 comments on commit d9bf761

Please sign in to comment.