Skip to content

Commit 81aaab7

Browse files
committed
benchmark: remove noAssert argument
This removes the `noAssert` argument and also adds some more tests. PR-URL: #18395 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent e8bb1f3 commit 81aaab7

File tree

5 files changed

+51
-33
lines changed

5 files changed

+51
-33
lines changed

benchmark/buffers/buffer-read-float.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
const common = require('../common.js');
33

44
const bench = common.createBenchmark(main, {
5-
noAssert: ['false', 'true'],
65
type: ['Double', 'Float'],
76
endian: ['BE', 'LE'],
87
value: ['zero', 'big', 'small', 'inf', 'nan'],
98
millions: [1]
109
});
1110

12-
function main({ noAssert, millions, type, endian, value }) {
13-
noAssert = noAssert === 'true';
11+
function main({ millions, type, endian, value }) {
1412
type = type || 'Double';
1513
const buff = Buffer.alloc(8);
1614
const fn = `read${type}${endian}`;
@@ -31,11 +29,11 @@ function main({ noAssert, millions, type, endian, value }) {
3129
},
3230
};
3331

34-
buff[`write${type}${endian}`](values[type][value], 0, noAssert);
32+
buff[`write${type}${endian}`](values[type][value], 0);
3533

3634
bench.start();
3735
for (var i = 0; i !== millions * 1e6; i++) {
38-
buff[fn](0, noAssert);
36+
buff[fn](0);
3937
}
4038
bench.end(millions);
4139
}

benchmark/buffers/buffer-read-with-byteLength.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ const types = [
99
];
1010

1111
const bench = common.createBenchmark(main, {
12-
noAssert: ['false', 'true'],
1312
buffer: ['fast', 'slow'],
1413
type: types,
1514
millions: [1],
16-
byteLength: [1, 2, 4, 6]
15+
byteLength: [1, 2, 3, 4, 5, 6]
1716
});
1817

19-
function main({ millions, noAssert, buf, type, byteLength }) {
20-
noAssert = noAssert === 'true';
21-
type = type || 'UInt8';
18+
function main({ millions, buf, type, byteLength }) {
2219
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
2320
const buff = new clazz(8);
24-
const fn = `read${type}`;
21+
const fn = `read${type || 'IntBE'}`;
2522

26-
buff.writeDoubleLE(0, 0, noAssert);
23+
buff.writeDoubleLE(0, 0);
2724
bench.start();
2825
for (var i = 0; i !== millions * 1e6; i++) {
29-
buff[fn](0, byteLength, noAssert);
26+
buff[fn](0, byteLength);
3027
}
3128
bench.end(millions);
3229
}

benchmark/buffers/buffer-read.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@ const types = [
1919
];
2020

2121
const bench = common.createBenchmark(main, {
22-
noAssert: ['false', 'true'],
2322
buffer: ['fast', 'slow'],
2423
type: types,
2524
millions: [1]
2625
});
2726

28-
function main({ noAssert, millions, buf, type }) {
29-
noAssert = noAssert === 'true';
27+
function main({ millions, buf, type }) {
3028
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
3129
const buff = new clazz(8);
3230
const fn = `read${type || 'UInt8'}`;
3331

34-
buff.writeDoubleLE(0, 0, noAssert);
32+
buff.writeDoubleLE(0, 0);
3533
bench.start();
3634
for (var i = 0; i !== millions * 1e6; i++) {
37-
buff[fn](0, noAssert);
35+
buff[fn](0);
3836
}
3937
bench.end(millions);
4038
}

benchmark/buffers/buffer-write.js

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ const types = [
77
'UInt16BE',
88
'UInt32LE',
99
'UInt32BE',
10+
'UIntLE',
11+
'UIntBE',
1012
'Int8',
1113
'Int16LE',
1214
'Int16BE',
1315
'Int32LE',
1416
'Int32BE',
17+
'IntLE',
18+
'IntBE',
1519
'FloatLE',
1620
'FloatBE',
1721
'DoubleLE',
1822
'DoubleBE'
1923
];
2024

2125
const bench = common.createBenchmark(main, {
22-
noAssert: ['false', 'true'],
2326
buffer: ['fast', 'slow'],
2427
type: types,
2528
millions: [1]
@@ -28,9 +31,9 @@ const bench = common.createBenchmark(main, {
2831
const INT8 = 0x7f;
2932
const INT16 = 0x7fff;
3033
const INT32 = 0x7fffffff;
31-
const UINT8 = (INT8 * 2) + 1;
32-
const UINT16 = (INT16 * 2) + 1;
33-
const UINT32 = INT32;
34+
const INT48 = 0x7fffffffffff;
35+
const UINT8 = 0xff;
36+
const UINT16 = 0xffff;
3437

3538
const mod = {
3639
writeInt8: INT8,
@@ -41,34 +44,57 @@ const mod = {
4144
writeUInt8: UINT8,
4245
writeUInt16BE: UINT16,
4346
writeUInt16LE: UINT16,
44-
writeUInt32BE: UINT32,
45-
writeUInt32LE: UINT32
47+
writeUInt32BE: INT32,
48+
writeUInt32LE: INT32,
49+
writeUIntLE: INT8,
50+
writeUIntBE: INT16,
51+
writeIntLE: INT32,
52+
writeIntBE: INT48
4653
};
4754

48-
function main({ noAssert, millions, buf, type }) {
55+
const byteLength = {
56+
writeUIntLE: 1,
57+
writeUIntBE: 2,
58+
writeIntLE: 4,
59+
writeIntBE: 6
60+
};
61+
62+
function main({ millions, buf, type }) {
4963
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
5064
const buff = new clazz(8);
5165
const fn = `write${type || 'UInt8'}`;
5266

53-
if (/Int/.test(fn))
54-
benchInt(buff, fn, millions, noAssert);
67+
if (!/\d/.test(fn))
68+
benchSpecialInt(buff, fn, millions);
69+
else if (/Int/.test(fn))
70+
benchInt(buff, fn, millions);
5571
else
56-
benchFloat(buff, fn, millions, noAssert);
72+
benchFloat(buff, fn, millions);
73+
}
74+
75+
function benchInt(buff, fn, millions) {
76+
const m = mod[fn];
77+
bench.start();
78+
for (var i = 0; i !== millions * 1e6; i++) {
79+
buff[fn](i & m, 0);
80+
}
81+
bench.end(millions);
5782
}
5883

59-
function benchInt(buff, fn, millions, noAssert) {
84+
function benchSpecialInt(buff, fn, millions) {
6085
const m = mod[fn];
86+
const byte = byteLength[fn];
6187
bench.start();
6288
for (var i = 0; i !== millions * 1e6; i++) {
63-
buff[fn](i & m, 0, noAssert);
89+
buff[fn](i & m, 0, byte);
6490
}
6591
bench.end(millions);
6692
}
6793

68-
function benchFloat(buff, fn, millions, noAssert) {
94+
function benchFloat(buff, fn, millions) {
6995
bench.start();
7096
for (var i = 0; i !== millions * 1e6; i++) {
71-
buff[fn](i, 0, noAssert);
97+
buff[fn](i, 0);
7298
}
7399
bench.end(millions);
74100
}

test/sequential/test-benchmark-buffer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ runBenchmark('buffers',
1616
'millions=0.000001',
1717
'method=',
1818
'n=1',
19-
'noAssert=true',
2019
'pieces=1',
2120
'pieceSize=1',
2221
'search=@',

0 commit comments

Comments
 (0)