0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/benchmark/misc/v8-bench.js
Bartosz Sosnowski 9e5a06ecf6 benchmark: make v8-bench.js output consistent
This changes the way v8-bench.js reports its performance to be consistent
with other benchmarks.

Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/8564
2016-09-26 17:23:49 +02:00

57 lines
1.4 KiB
JavaScript

// compare with "google-chrome deps/v8/benchmarks/run.html"
'use strict';
var fs = require('fs');
var path = require('path');
var vm = require('vm');
var common = require('../common.js');
var dir = path.join(__dirname, '..', '..', 'deps', 'v8', 'benchmarks');
function load(filename, inGlobal) {
var source = fs.readFileSync(path.join(dir, filename), 'utf8');
if (!inGlobal) source = '(function () {' + source + '\n})()';
vm.runInThisContext(source, { filename: 'v8/bechmark/' + filename });
}
load('base.js', true);
load('richards.js');
load('deltablue.js');
load('crypto.js');
load('raytrace.js');
load('earley-boyer.js');
load('regexp.js');
load('splay.js');
load('navier-stokes.js');
const benchmark_name = path.join('misc', 'v8-bench.js');
const times = {};
global.BenchmarkSuite.RunSuites({
NotifyStart: function(name) {
times[name] = process.hrtime();
},
NotifyResult: function(name, result) {
const elapsed = process.hrtime(times[name]);
common.sendResult({
name: benchmark_name,
conf: {
benchmark: name
},
rate: result,
time: elapsed[0] + elapsed[1] / 1e9
});
},
NotifyError: function(name, error) {
console.error(name + ': ' + error);
},
NotifyScore: function(score) {
common.sendResult({
name: benchmark_name,
conf: {
benchmark: 'Score (version ' + global.BenchmarkSuite.version + ')'
},
rate: score,
time: 0
});
}
});