mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Enable node:ffi by default in builds with FFI support. Keep --experimental-ffi as a compatibility no-op and --no-experimental-ffi as an opt-out. Loading the module still emits an experimental warning. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/65475 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
29 lines
623 B
JavaScript
29 lines
623 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, {
|
|
n: [1e7],
|
|
});
|
|
|
|
ensureFixtureLibrary();
|
|
|
|
const { lib, functions } = ffi.dlopen(libraryPath, {
|
|
pointer_to_usize: { return: 'u64', arguments: ['pointer'] },
|
|
});
|
|
|
|
const fn = functions.pointer_to_usize;
|
|
const bytes = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
const pointer = ffi.getRawPointer(bytes);
|
|
|
|
function main({ n }) {
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i)
|
|
fn(pointer);
|
|
bench.end(n);
|
|
|
|
lib.close();
|
|
}
|