-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathsum-buffer.js
More file actions
33 lines (25 loc) · 707 Bytes
/
sum-buffer.js
File metadata and controls
33 lines (25 loc) · 707 Bytes
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
'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: { result: 'u64', parameters: ['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();
}