Skip to content

Commit c721d68

Browse files
thisalihassanaduh95
authored andcommitted
benchmark: fix destructuring in dgram/single-buffer
PR #59872 renamed the config key from `num` to `n` but did not update the destructuring in main(), leaving `{ num: n }` which resolves to undefined. This caused the benchmark to produce near-zero throughput since the send-batching logic never fires when n is undefined. Refs: #59872 PR-URL: #62084 Refs: nodejs/performance#187 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 409b066 commit c721d68

4 files changed

Lines changed: 26 additions & 26 deletions

File tree

‎benchmark/crypto/hash-stream-creation.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const common = require('../common.js');
55
constcrypto=require('crypto');
66

77
constbench=common.createBenchmark(main,{
8-
writes: [500],
8+
n: [500],
99
algo: ['sha256','md5'],
1010
type: ['asc','utf','buf'],
1111
out: ['hex','binary','buffer'],
1212
len: [2,1024,102400,1024*1024],
1313
api: ['legacy','stream'],
1414
});
1515

16-
functionmain({ api, type, len, out,writes, algo }){
16+
functionmain({ api, type, len, out,n, algo }){
1717
if(api==='stream'&&/^v0\.[0-8]\./.test(process.version)){
1818
console.error('Crypto streams not available until v0.10');
1919
// Use the legacy, just so that we can compare them.
@@ -41,15 +41,15 @@ function main({ api, type, len, out, writes, algo }) {
4141
constfn=api==='stream' ? streamWrite : legacyWrite;
4242

4343
bench.start();
44-
fn(algo,message,encoding,writes,len,out);
44+
fn(algo,message,encoding,n,len,out);
4545
}
4646

47-
functionlegacyWrite(algo,message,encoding,writes,len,outEnc){
48-
constwritten=writes*len;
47+
functionlegacyWrite(algo,message,encoding,n,len,outEnc){
48+
constwritten=n*len;
4949
constbits=written*8;
5050
constgbits=bits/(1024*1024*1024);
5151

52-
while(writes-->0){
52+
while(n-->0){
5353
consth=crypto.createHash(algo);
5454
h.update(message,encoding);
5555
h.digest(outEnc);
@@ -58,12 +58,12 @@ function legacyWrite(algo, message, encoding, writes, len, outEnc) {
5858
bench.end(gbits);
5959
}
6060

61-
functionstreamWrite(algo,message,encoding,writes,len,outEnc){
62-
constwritten=writes*len;
61+
functionstreamWrite(algo,message,encoding,n,len,outEnc){
62+
constwritten=n*len;
6363
constbits=written*8;
6464
constgbits=bits/(1024*1024*1024);
6565

66-
while(writes-->0){
66+
while(n-->0){
6767
consth=crypto.createHash(algo);
6868

6969
if(outEnc!=='buffer')

‎benchmark/crypto/hash-stream-throughput.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const common = require('../common.js');
55
constcrypto=require('crypto');
66

77
constbench=common.createBenchmark(main,{
8-
writes: [500],
8+
n: [500],
99
algo: ['sha1','sha256','sha512'],
1010
type: ['asc','utf','buf'],
1111
len: [2,1024,102400,1024*1024],
1212
api: ['legacy','stream'],
1313
});
1414

15-
functionmain({ api, type, len, algo,writes}){
15+
functionmain({ api, type, len, algo,n}){
1616
if(api==='stream'&&/^v0\.[0-8]\./.test(process.version)){
1717
console.error('Crypto streams not available until v0.10');
1818
// Use the legacy, just so that we can compare them.
@@ -40,30 +40,30 @@ function main({ api, type, len, algo, writes }) {
4040
constfn=api==='stream' ? streamWrite : legacyWrite;
4141

4242
bench.start();
43-
fn(algo,message,encoding,writes,len);
43+
fn(algo,message,encoding,n,len);
4444
}
4545

46-
functionlegacyWrite(algo,message,encoding,writes,len){
47-
constwritten=writes*len;
46+
functionlegacyWrite(algo,message,encoding,n,len){
47+
constwritten=n*len;
4848
constbits=written*8;
4949
constgbits=bits/(1024*1024*1024);
5050
consth=crypto.createHash(algo);
5151

52-
while(writes-->0)
52+
while(n-->0)
5353
h.update(message,encoding);
5454

5555
h.digest();
5656

5757
bench.end(gbits);
5858
}
5959

60-
functionstreamWrite(algo,message,encoding,writes,len){
61-
constwritten=writes*len;
60+
functionstreamWrite(algo,message,encoding,n,len){
61+
constwritten=n*len;
6262
constbits=written*8;
6363
constgbits=bits/(1024*1024*1024);
6464
consth=crypto.createHash(algo);
6565

66-
while(writes-->0)
66+
while(n-->0)
6767
h.write(message,encoding);
6868

6969
h.end();

‎benchmark/crypto/rsa-sign-verify-throughput.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ keylen_list.forEach((key) => {
1717
});
1818

1919
constbench=common.createBenchmark(main,{
20-
writes: [500],
20+
n: [500],
2121
algo: ['SHA1','SHA224','SHA256','SHA384','SHA512'],
2222
keylen: keylen_list,
2323
len: [1024,102400,2*102400,3*102400,1024*1024],
2424
});
2525

26-
functionmain({ len, algo, keylen,writes}){
26+
functionmain({ len, algo, keylen,n}){
2727
constmessage=Buffer.alloc(len,'b');
2828
bench.start();
29-
StreamWrite(algo,keylen,message,writes,len);
29+
StreamWrite(algo,keylen,message,n,len);
3030
}
3131

32-
functionStreamWrite(algo,keylen,message,writes,len){
33-
constwritten=writes*len;
32+
functionStreamWrite(algo,keylen,message,n,len){
33+
constwritten=n*len;
3434
constbits=written*8;
3535
constkbits=bits/(1024);
3636

3737
constprivateKey=RSA_PrivatePem[keylen];
3838
consts=crypto.createSign(algo);
3939
constv=crypto.createVerify(algo);
4040

41-
while(writes-->0){
41+
while(n-->0){
4242
s.update(message);
4343
v.update(message);
4444
}

‎benchmark/dgram/single-buffer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const common = require('../common.js');
55
constdgram=require('dgram');
66
constPORT=common.PORT;
77

8-
// `num` is the number of send requests to queue up each time.
8+
// `n` is the number of send requests to queue up each time.
99
// Keep it reasonably high (>10) otherwise you're benchmarking the speed of
1010
// event loop cycles more than anything else.
1111
constbench=common.createBenchmark(main,{
@@ -15,7 +15,7 @@ const bench = common.createBenchmark(main, {
1515
dur: [5],
1616
});
1717

18-
functionmain({ dur, len,num: n, type }){
18+
functionmain({ dur, len, n, type }){
1919
constchunk=Buffer.allocUnsafe(len);
2020
letsent=0;
2121
letreceived=0;

0 commit comments

Comments
 (0)