Skip to content

Commit aa2fca1

Browse files
committed
add benchmark
1 parent 3cf7088 commit aa2fca1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

benchmark/buffers/fast-buffer.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
// flags: --expose-internals
4+
5+
const common = require('../common');
6+
const { FastBuffer } = require('internal/buffer');
7+
8+
const bench = common.createBenchmark(main, {
9+
n: [1e6],
10+
operation: ['fastbuffer', 'bufferalloc'],
11+
});
12+
13+
14+
function main({ n, operation }) {
15+
switch (operation) {
16+
case 'fastbuffer':
17+
bench.start();
18+
for (let i = 0; i < n; i++) {
19+
new FastBuffer();
20+
}
21+
bench.end(n);
22+
break;
23+
case 'bufferalloc':
24+
bench.start();
25+
for (let i = 0; i < n; i++) {
26+
Buffer.alloc(0);
27+
}
28+
bench.end(n);
29+
break;
30+
}
31+
}

0 commit comments

Comments
 (0)