-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add assert.deep[Strict]Equal benchmarks
* Move numbers into configuration * Add buffer comparison benchmark * Add assert.deepStrictEqual benchmarks PR-URL: #11092 Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
1fbbcc3
commit 8f34181
Showing
4 changed files
with
134 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const assert = require('assert'); | ||
const bench = common.createBenchmark(main, { | ||
n: [1e3], | ||
len: [1e2], | ||
method: ['strict', 'nonstrict'] | ||
}); | ||
|
||
function main(conf) { | ||
const n = +conf.n; | ||
const len = +conf.len; | ||
var i; | ||
|
||
const data = Buffer.allocUnsafe(len); | ||
const actual = Buffer.alloc(len); | ||
const expected = Buffer.alloc(len); | ||
data.copy(actual); | ||
data.copy(expected); | ||
|
||
switch (conf.method) { | ||
case 'strict': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
// eslint-disable-next-line no-restricted-properties | ||
assert.deepEqual(actual, expected); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'nonstrict': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
assert.deepStrictEqual(actual, expected); | ||
} | ||
bench.end(n); | ||
break; | ||
default: | ||
throw new Error('Unsupported method'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var assert = require('assert'); | ||
var bench = common.createBenchmark(main, { | ||
const common = require('../common.js'); | ||
const assert = require('assert'); | ||
const bench = common.createBenchmark(main, { | ||
type: ('Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array ' + | ||
'Float32Array Float64Array Uint8ClampedArray').split(' '), | ||
n: [1] | ||
n: [1], | ||
method: ['strict', 'nonstrict'], | ||
len: [1e6] | ||
}); | ||
|
||
function main(conf) { | ||
var type = conf.type; | ||
var clazz = global[type]; | ||
var n = +conf.n; | ||
const type = conf.type; | ||
const clazz = global[type]; | ||
const n = +conf.n; | ||
const len = +conf.len; | ||
|
||
bench.start(); | ||
var actual = new clazz(n * 1e6); | ||
var expected = new clazz(n * 1e6); | ||
const actual = new clazz(len); | ||
const expected = new clazz(len); | ||
var i; | ||
|
||
// eslint-disable-next-line no-restricted-properties | ||
assert.deepEqual(actual, expected); | ||
|
||
bench.end(n); | ||
switch (conf.method) { | ||
case 'strict': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
// eslint-disable-next-line no-restricted-properties | ||
assert.deepEqual(actual, expected); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'nonstrict': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
assert.deepStrictEqual(actual, expected); | ||
} | ||
bench.end(n); | ||
break; | ||
default: | ||
throw new Error('Unsupported method'); | ||
} | ||
} |