Skip to content

Commit 54c22ae

Browse files
committed
Added a benchmark runner + profile option
1 parent a9929c9 commit 54c22ae

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

Makefile

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
ALL_TESTS = $(shell find test/ -name '*.test.js')
3+
ALL_BENCH = $(shell find benchmarks -name '*.bench.js')
34

45
run-tests:
56
@./node_modules/.bin/expresso \
@@ -19,8 +20,13 @@ test-cov:
1920
test-leaks:
2021
@ls test/leaks/* | xargs node --expose_debug_as=debug --expose_gc
2122

23+
run-bench:
24+
@node $(PROFILEFLAGS) benchmarks/runner.js
25+
2226
bench:
23-
@node benchmarks/encode \
24-
&& node benchmarks/decode
27+
@$(MAKE) BENCHMARKS="$(ALL_BENCH)" run-bench
28+
29+
profile:
30+
@PROFILEFLAGS='--prof --trace-opt --trace-bailout --trace-deopt' $(MAKE) bench
2531

26-
.PHONY: test bench
32+
.PHONY: test bench profile
File renamed without changes.
File renamed without changes.

benchmarks/runner.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Benchmark runner dependencies
3+
*/
4+
5+
var colors = require('colors')
6+
, path = require('path');
7+
8+
/**
9+
* Find all the benchmarks
10+
*/
11+
12+
var benchmarks_files = process.env.BENCHMARKS.split(' ')
13+
, all = [].concat(benchmarks_files)
14+
, first = all.shift()
15+
, benchmarks = {};
16+
17+
// find the benchmarks and load them all in our obj
18+
benchmarks_files.forEach(function (file) {
19+
benchmarks[file] = require(path.join(__dirname, '..', file));
20+
});
21+
22+
// setup the complete listeners
23+
benchmarks_files.forEach(function (file) {
24+
var benchmark = benchmarks[file]
25+
, next_file = all.shift()
26+
, next = benchmarks[next_file];
27+
28+
/**
29+
* Generate a oncomplete function for the tests, either we are done or we
30+
* have more benchmarks to process.
31+
*/
32+
33+
function complete () {
34+
if (!next) {
35+
console.log(
36+
'\n\nBenchmark completed in'.grey
37+
, (Date.now() - start).toString().green + ' ms'.grey
38+
);
39+
} else {
40+
console.log('\nStarting benchmark '.grey + next_file.yellow);
41+
next.run();
42+
}
43+
}
44+
45+
// attach the listener
46+
benchmark.on('complete', complete);
47+
});
48+
49+
/**
50+
* Start the benchmark
51+
*/
52+
53+
var start = Date.now();
54+
console.log('Starting benchmark '.grey + first.yellow);
55+
benchmarks[first].run();

0 commit comments

Comments
 (0)