forked from nodejs/node-addon-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty_descriptor.js
More file actions
37 lines (31 loc) · 1.03 KB
/
property_descriptor.js
File metadata and controls
37 lines (31 loc) · 1.03 KB
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
const path = require('path');
const Benchmark = require('benchmark');
const addonName = path.basename(__filename, '.js');
[ addonName, addonName + '_noexcept' ]
.forEach((addonName) => {
const rootAddon = require('bindings')({
bindings: addonName,
module_root: __dirname
});
delete rootAddon.path;
const getters = new Benchmark.Suite;
const setters = new Benchmark.Suite;
const maxNameLength = Object.keys(rootAddon)
.reduce((soFar, value) => Math.max(soFar, value.length), 0);
console.log(`\n${addonName}: `);
Object.keys(rootAddon).forEach((key) => {
getters.add(`${key} getter`.padStart(maxNameLength + 7), () => {
const x = rootAddon[key];
});
setters.add(`${key} setter`.padStart(maxNameLength + 7), () => {
rootAddon[key] = 5;
})
});
getters
.on('cycle', (event) => console.log(String(event.target)))
.run();
console.log('');
setters
.on('cycle', (event) => console.log(String(event.target)))
.run();
});