Skip to content

Commit 3ab6143

Browse files
joyeecheungrichardlau
authored andcommitted
benchmark: add create-hash benchmark
PR-URL: #51026 Refs: nodejs/performance#136 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 09ad974 commit 3ab6143

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

‎benchmark/crypto/create-hash.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
constcommon=require('../common.js');
4+
const{ createHash }=require('crypto');
5+
constassert=require('assert');
6+
7+
constbench=common.createBenchmark(main,{
8+
n: [1e5],
9+
});
10+
11+
functionmain({ n }){
12+
constarray=[];
13+
for(leti=0;i<n;++i){
14+
array.push(null);
15+
}
16+
bench.start();
17+
for(leti=0;i<n;++i){
18+
array[i]=createHash('sha1');
19+
}
20+
bench.end(n);
21+
assert.strictEqual(typeofarray[n-1],'object');
22+
}

‎lib/internal/crypto/hash.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const kState = Symbol('kState');
5757
constkFinalized=Symbol('kFinalized');
5858

5959
functionHash(algorithm,options){
60-
if(!(thisinstanceofHash))
60+
if(!new.target)
6161
returnnewHash(algorithm,options);
6262
if(!(algorithminstanceof_Hash))
6363
validateString(algorithm,'algorithm');

0 commit comments

Comments
(0)