summaryrefslogtreecommitdiff
path: root/benchmark/misc/v8-bench.js
blob: fe004251cb6cbe2b053e958de3c2d51337007502 (plain)
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
// compare with "google-chrome deps/v8/benchmarks/run.html"
'use strict';
const fs = require('fs');
const path = require('path');
const vm = require('vm');
const common = require('../common.js');

const 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
    });
  }
});