Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b148c43

Browse filesBrowse files
joyeecheungRafaelGSS
authored andcommitted
benchmark: add create-hash benchmark
PR-URL: #51026 Refs: nodejs/performance#136 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent c45a9a3 commit b148c43
Copy full SHA for b148c43

File tree

Expand file treeCollapse file tree

2 files changed

+23
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-1
lines changed
Open diff view settings
Collapse file

‎benchmark/crypto/create-hash.js‎

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

‎lib/internal/crypto/hash.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/hash.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const kState = Symbol('kState');
5757
const kFinalized = Symbol('kFinalized');
5858

5959
function Hash(algorithm, options) {
60-
if (!(this instanceof Hash))
60+
if (!new.target)
6161
return new Hash(algorithm, options);
6262
if (!(algorithm instanceof _Hash))
6363
validateString(algorithm, 'algorithm');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.