-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert: typed array deepequal performance fix #4330
Closed
claudiorodriguez
wants to merge
1
commit into
nodejs:master
from
claudiorodriguez:assert-performance-typed-arrays
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,37 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var assert = require('assert'); | ||
var bench = common.createBenchmark(main, { | ||
prim: [ | ||
null, | ||
undefined, | ||
'a', | ||
1, | ||
true, | ||
{0: 'a'}, | ||
[1, 2, 3], | ||
new Array([1, 2, 3]) | ||
], | ||
n: [25] | ||
}); | ||
|
||
function main(conf) { | ||
var prim = conf.prim; | ||
var n = +conf.n; | ||
var primArray; | ||
var primArrayCompare; | ||
var x; | ||
|
||
primArray = new Array(); | ||
primArrayCompare = new Array(); | ||
for (x = 0; x < (1e5); x++) { | ||
primArray.push(prim); | ||
primArrayCompare.push(prim); | ||
} | ||
|
||
bench.start(); | ||
for (x = 0; x < n; x++) { | ||
assert.deepEqual(primArray, primArrayCompare); | ||
} | ||
bench.end(n); | ||
} |
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,30 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var assert = require('assert'); | ||
var bench = common.createBenchmark(main, { | ||
prim: [ | ||
null, | ||
undefined, | ||
'a', | ||
1, | ||
true, | ||
{0: 'a'}, | ||
[1, 2, 3], | ||
new Array([1, 2, 3]) | ||
], | ||
n: [1e5] | ||
}); | ||
|
||
function main(conf) { | ||
var prim = conf.prim; | ||
var n = +conf.n; | ||
var x; | ||
|
||
bench.start(); | ||
|
||
for (x = 0; x < n; x++) { | ||
assert.deepEqual(new Array([prim]), new Array([prim])); | ||
} | ||
|
||
bench.end(n); | ||
} |
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,22 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var assert = require('assert'); | ||
var bench = common.createBenchmark(main, { | ||
type: ('Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array ' + | ||
'Float32Array Float64Array Uint8ClampedArray').split(' '), | ||
n: [1] | ||
}); | ||
|
||
function main(conf) { | ||
var type = conf.type; | ||
var clazz = global[type]; | ||
var n = +conf.n; | ||
|
||
bench.start(); | ||
var actual = new clazz(n * 1e6); | ||
var expected = new clazz(n * 1e6); | ||
|
||
assert.deepEqual(actual, expected); | ||
|
||
bench.end(n); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const a = require('assert'); | ||
|
||
function makeBlock(f) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return function() { | ||
return f.apply(this, args); | ||
}; | ||
} | ||
|
||
const equalArrayPairs = [ | ||
[new Uint8Array(1e5), new Uint8Array(1e5)], | ||
[new Uint16Array(1e5), new Uint16Array(1e5)], | ||
[new Uint32Array(1e5), new Uint32Array(1e5)], | ||
[new Uint8ClampedArray(1e5), new Uint8ClampedArray(1e5)], | ||
[new Int8Array(1e5), new Int8Array(1e5)], | ||
[new Int16Array(1e5), new Int16Array(1e5)], | ||
[new Int32Array(1e5), new Int32Array(1e5)], | ||
[new Float32Array(1e5), new Float32Array(1e5)], | ||
[new Float64Array(1e5), new Float64Array(1e5)] | ||
]; | ||
|
||
const notEqualArrayPairs = [ | ||
[new Uint8Array(2), new Uint8Array(3)], | ||
[new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])], | ||
[new Uint8ClampedArray([300, 2, 3]), new Uint8Array([300, 2, 3])] | ||
]; | ||
|
||
equalArrayPairs.forEach((arrayPair) => { | ||
assert.deepEqual(arrayPair[0], arrayPair[1]); | ||
}); | ||
|
||
notEqualArrayPairs.forEach((arrayPair) => { | ||
assert.throws( | ||
makeBlock(a.deepEqual, arrayPair[0], arrayPair[1]), | ||
a.AssertionError | ||
); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please
require('../common');
.