Skip to content

Commit afe014c

Browse files
committed
benchmark: try building the addons in napi benchmarks
1 parent ce6ec36 commit afe014c

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

benchmark/common.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
const child_process = require('child_process');
44
const http_benchmarkers = require('./_http-benchmarkers.js');
5+
const path = require('path');
6+
7+
exports.buildAddon = function(directory) {
8+
const root = path.join(__dirname, '../');
9+
const gyp = path.join(root, 'deps/npm/node_modules/node-gyp/bin/node-gyp');
10+
const python = process.env.PYTHON || 'python';
11+
const ret = child_process.spawnSync(process.execPath, [
12+
gyp,
13+
'rebuild',
14+
`--python=${python}`,
15+
`--directory=${path.join(root, directory)}`,
16+
`--nodedir=${root}`
17+
], { env: { ...process.env, MAKEFLAGS: '-j1' }});
18+
if (ret.error || ret.status !== 0) {
19+
console.error('ERROR', ret.error);
20+
console.error('STATUS', ret.status);
21+
console.error('---- stdout ----');
22+
console.error(ret.stdout.toString());
23+
console.error('---- stderr ----');
24+
console.error(ret.stderr.toString());
25+
throw new Error(`Failed to build ${directory}`);
26+
}
27+
};
528

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

benchmark/napi/function_args/index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,29 @@ let napi;
1212
try {
1313
v8 = require(`./build/${common.buildType}/binding`);
1414
} catch {
15-
console.error(`${__filename}: V8 Binding failed to load`);
16-
process.exit(0);
15+
try {
16+
common.buildAddon('benchmark/napi/function_args');
17+
// eslint-disable-next-line node-core/no-duplicate-requires
18+
v8 = require(`./build/${common.buildType}/binding`);
19+
} catch (e) {
20+
console.error(`${__filename}: V8 Binding failed to load`);
21+
console.error(e);
22+
process.exit(0);
23+
}
1724
}
1825

1926
try {
2027
napi = require(`./build/${common.buildType}/napi_binding`);
2128
} catch {
22-
console.error(`${__filename}: NAPI-Binding failed to load`);
23-
process.exit(0);
29+
try {
30+
common.buildAddon('benchmark/napi/function_args');
31+
// eslint-disable-next-line node-core/no-duplicate-requires
32+
napi = require(`./build/${common.buildType}/napi_binding`);
33+
} catch (e) {
34+
console.error(`${__filename}: N-API Binding failed to load`);
35+
console.error(e);
36+
process.exit(0);
37+
}
2438
}
2539

2640
const argsTypes = ['String', 'Number', 'Object', 'Array', 'Typedarray',

benchmark/napi/function_call/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,39 @@
66

77
const assert = require('assert');
88
const common = require('../../common.js');
9-
109
// this fails when we try to open with a different version of node,
1110
// which is quite common for benchmarks. so in that case, just
1211
// abort quietly.
1312

13+
let binding;
1414
try {
15-
var binding = require(`./build/${common.buildType}/binding`);
15+
binding = require(`./build/${common.buildType}/binding`);
1616
} catch {
17-
console.error('misc/function_call.js Binding failed to load');
18-
process.exit(0);
17+
try {
18+
common.buildAddon('benchmark/napi/function_call');
19+
// eslint-disable-next-line node-core/no-duplicate-requires
20+
binding = require(`./build/${common.buildType}/binding`);
21+
} catch (e) {
22+
console.error(`${__filename}: V8 Binding failed to load`);
23+
console.error(e);
24+
process.exit(0);
25+
}
1926
}
2027
const cxx = binding.hello;
2128

2229
let napi_binding;
2330
try {
2431
napi_binding = require(`./build/${common.buildType}/napi_binding`);
2532
} catch {
26-
console.error('misc/function_call/index.js NAPI-Binding failed to load');
27-
process.exit(0);
33+
try {
34+
common.buildAddon('benchmark/misc/function_call');
35+
// eslint-disable-next-line node-core/no-duplicate-requires
36+
napi_binding = require(`./build/${common.buildType}/napi_binding`);
37+
} catch (e) {
38+
console.error(`${__filename}: N-API Binding failed to load`);
39+
console.error(e);
40+
process.exit(0);
41+
}
2842
}
2943
const napi = napi_binding.hello;
3044

0 commit comments

Comments
 (0)