Skip to content

Commit

Permalink
benchmark: try building the addons in napi benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Nov 11, 2018
1 parent ce6ec36 commit afe014c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
23 changes: 23 additions & 0 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

const child_process = require('child_process');
const http_benchmarkers = require('./_http-benchmarkers.js');
const path = require('path');

exports.buildAddon = function(directory) {
const root = path.join(__dirname, '../');
const gyp = path.join(root, 'deps/npm/node_modules/node-gyp/bin/node-gyp');
const python = process.env.PYTHON || 'python';
const ret = child_process.spawnSync(process.execPath, [
gyp,
'rebuild',
`--python=${python}`,
`--directory=${path.join(root, directory)}`,
`--nodedir=${root}`
], { env: { ...process.env, MAKEFLAGS: '-j1' }});
if (ret.error || ret.status !== 0) {
console.error('ERROR', ret.error);
console.error('STATUS', ret.status);
console.error('---- stdout ----');
console.error(ret.stdout.toString());
console.error('---- stderr ----');
console.error(ret.stderr.toString());
throw new Error(`Failed to build ${directory}`);
}
};

exports.buildType = process.features.debug ? 'Debug' : 'Release';

Expand Down
22 changes: 18 additions & 4 deletions benchmark/napi/function_args/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,29 @@ let napi;
try {
v8 = require(`./build/${common.buildType}/binding`);
} catch {
console.error(`${__filename}: V8 Binding failed to load`);
process.exit(0);
try {
common.buildAddon('benchmark/napi/function_args');
// eslint-disable-next-line node-core/no-duplicate-requires
v8 = require(`./build/${common.buildType}/binding`);
} catch (e) {
console.error(`${__filename}: V8 Binding failed to load`);
console.error(e);
process.exit(0);
}
}

try {
napi = require(`./build/${common.buildType}/napi_binding`);
} catch {
console.error(`${__filename}: NAPI-Binding failed to load`);
process.exit(0);
try {
common.buildAddon('benchmark/napi/function_args');
// eslint-disable-next-line node-core/no-duplicate-requires
napi = require(`./build/${common.buildType}/napi_binding`);
} catch (e) {
console.error(`${__filename}: N-API Binding failed to load`);
console.error(e);
process.exit(0);
}
}

const argsTypes = ['String', 'Number', 'Object', 'Array', 'Typedarray',
Expand Down
26 changes: 20 additions & 6 deletions benchmark/napi/function_call/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,39 @@

const assert = require('assert');
const common = require('../../common.js');

// this fails when we try to open with a different version of node,
// which is quite common for benchmarks. so in that case, just
// abort quietly.

let binding;
try {
var binding = require(`./build/${common.buildType}/binding`);
binding = require(`./build/${common.buildType}/binding`);
} catch {
console.error('misc/function_call.js Binding failed to load');
process.exit(0);
try {
common.buildAddon('benchmark/napi/function_call');
// eslint-disable-next-line node-core/no-duplicate-requires
binding = require(`./build/${common.buildType}/binding`);
} catch (e) {
console.error(`${__filename}: V8 Binding failed to load`);
console.error(e);
process.exit(0);
}
}
const cxx = binding.hello;

let napi_binding;
try {
napi_binding = require(`./build/${common.buildType}/napi_binding`);
} catch {
console.error('misc/function_call/index.js NAPI-Binding failed to load');
process.exit(0);
try {
common.buildAddon('benchmark/misc/function_call');
// eslint-disable-next-line node-core/no-duplicate-requires
napi_binding = require(`./build/${common.buildType}/napi_binding`);
} catch (e) {
console.error(`${__filename}: N-API Binding failed to load`);
console.error(e);
process.exit(0);
}
}
const napi = napi_binding.hello;

Expand Down

0 comments on commit afe014c

Please sign in to comment.