fcs
2025-04-10 0163870d662dc5b7d69ceff977490ede594f7d82
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
57
58
59
60
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 implems = Object.keys(rootAddon);
    const maxNameLength =
      implems.reduce((soFar, value) => Math.max(soFar, value.length), 0);
    const anObject = {};
 
    console.log(`\n${addonName}: `);
 
    console.log('no arguments:');
    implems.reduce((suite, implem) => {
      const fn = rootAddon[implem].noArgFunction;
      return suite.add(implem.padStart(maxNameLength, ' '), () => fn());
    }, new Benchmark.Suite)
      .on('cycle', (event) => console.log(String(event.target)))
      .run();
 
    console.log('one argument:');
    implems.reduce((suite, implem) => {
      const fn = rootAddon[implem].oneArgFunction;
      return suite.add(implem.padStart(maxNameLength, ' '), () => fn('x'));
    }, new Benchmark.Suite)
      .on('cycle', (event) => console.log(String(event.target)))
      .run();
 
    console.log('two arguments:');
    implems.reduce((suite, implem) => {
      const fn = rootAddon[implem].twoArgFunction;
      return suite.add(implem.padStart(maxNameLength, ' '), () => fn('x', 12));
    }, new Benchmark.Suite)
      .on('cycle', (event) => console.log(String(event.target)))
      .run();
 
    console.log('three arguments:');
    implems.reduce((suite, implem) => {
      const fn = rootAddon[implem].threeArgFunction;
      return suite.add(implem.padStart(maxNameLength, ' '),
        () => fn('x', 12, true));
    }, new Benchmark.Suite)
      .on('cycle', (event) => console.log(String(event.target)))
      .run();
 
    console.log('four arguments:');
    implems.reduce((suite, implem) => {
      const fn = rootAddon[implem].fourArgFunction;
      return suite.add(implem.padStart(maxNameLength, ' '),
        () => fn('x', 12, true, anObject));
    }, new Benchmark.Suite)
      .on('cycle', (event) => console.log(String(event.target)))
      .run();
  });