Follow-up to df09b2a48c.
Refs: https://github.com/nodejs/node/pull/63482
Signed-off-by: Anna Henningsen <anna@addaleax.net>
PR-URL: https://github.com/nodejs/node/pull/63666
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
33 lines
706 B
JavaScript
33 lines
706 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
const ffi = require('node:ffi');
|
|
const { libraryPath, ensureFixtureLibrary } = require('./common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
size: [64, 1024, 16384],
|
|
n: [1e6],
|
|
}, {
|
|
flags: ['--experimental-ffi'],
|
|
});
|
|
|
|
ensureFixtureLibrary();
|
|
|
|
const { lib, functions } = ffi.dlopen(libraryPath, {
|
|
sum_buffer: { return: 'u64', arguments: ['pointer', 'u64'] },
|
|
});
|
|
|
|
function main({ n, size }) {
|
|
const buf = Buffer.alloc(size, 0x42);
|
|
const ptr = ffi.getRawPointer(buf);
|
|
const len = BigInt(size);
|
|
|
|
const sum = functions.sum_buffer;
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i)
|
|
sum(ptr, len);
|
|
bench.end(n);
|
|
|
|
lib.close();
|
|
}
|