| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7485309 commit 1ded5f2
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,7 @@ function benchmark(method, n, values, values2) { | |||
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | 33 | function main({ n, len, method, strict }) { | |
| 34 | - const array = Array(len).fill(1); | ||
| 34 | + const array = Array.from({ length: len }, () => ''); | ||
| 35 | 35 | ||
| 36 | 36 | switch (method) { | |
| 37 | 37 | case 'deepEqual_primitiveOnly': { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,6 @@ const primValues = { | |||
| 14 | 14 | 'number': 1_000, | |
| 15 | 15 | 'boolean': true, | |
| 16 | 16 | 'object': { property: 'abcdef' }, | |
| 17 | - 'object_other_property': { property: 'abcdef' }, | ||
| 18 | 17 | 'array': [1, 2, 3], | |
| 19 | 18 | 'set_object': new Set([[1]]), | |
| 20 | 19 | 'set_simple': new Set([1, 2, 3]), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,8 +6,9 @@ const { deepEqual, deepStrictEqual, notDeepEqual, notDeepStrictEqual } = | |||
| 6 | 6 | ||
| 7 | 7 | const bench = common.createBenchmark(main, { | |
| 8 | 8 | n: [1e3], | |
| 9 | - len: [5e2], | ||
| 9 | + len: [2, 1e2], | ||
| 10 | 10 | strict: [0, 1], | |
| 11 | + order: ['insert', 'random', 'reversed'], | ||
| 11 | 12 | method: [ | |
| 12 | 13 | 'deepEqual_primitiveOnly', | |
| 13 | 14 | 'deepEqual_objectOnly', | |
@@ -16,12 +17,30 @@ const bench = common.createBenchmark(main, { | |||
| 16 | 17 | 'notDeepEqual_objectOnly', | |
| 17 | 18 | 'notDeepEqual_mixed', | |
| 18 | 19 | ], | |
| 20 | + }, { | ||
| 21 | + combinationFilter(p) { | ||
| 22 | + return p.order !== 'random' || p.strict === 1 && p.method !== 'notDeepEqual_objectOnly'; | ||
| 23 | + }, | ||
| 19 | 24 | }); | |
| 20 | 25 | ||
| 21 | - function benchmark(method, n, values, values2) { | ||
| 26 | + function shuffleArray(array) { | ||
| 27 | + for (let i = array.length - 1; i > 0; i--) { | ||
| 28 | + const j = Math.floor(Math.random() * (i + 1)); | ||
| 29 | + const temp = array[i]; | ||
| 30 | + array[i] = array[j]; | ||
| 31 | + array[j] = temp; | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + function benchmark(method, n, values, values2, order) { | ||
| 22 | 36 | const actual = new Set(values); | |
| 23 | 37 | // Prevent reference equal elements | |
| 24 | - const deepCopy = JSON.parse(JSON.stringify(values2 ? values2 : values)); | ||
| 38 | + let deepCopy = JSON.parse(JSON.stringify(values2)); | ||
| 39 | + if (order === 'reversed') { | ||
| 40 | + deepCopy = deepCopy.reverse(); | ||
| 41 | + } else if (order === 'random') { | ||
| 42 | + shuffleArray(deepCopy); | ||
| 43 | + } | ||
| 25 | 44 | const expected = new Set(deepCopy); | |
| 26 | 45 | bench.start(); | |
| 27 | 46 | for (let i = 0; i < n; ++i) { | |
@@ -30,39 +49,39 @@ function benchmark(method, n, values, values2) { | |||
| 30 | 49 | bench.end(n); | |
| 31 | 50 | } | |
| 32 | 51 | ||
| 33 | - function main({ n, len, method, strict }) { | ||
| 34 | - const array = Array(len).fill(1); | ||
| 52 | + function main({ n, len, method, strict, order }) { | ||
| 53 | + const array = Array.from({ length: len }, () => ''); | ||
| 35 | 54 | ||
| 36 | 55 | switch (method) { | |
| 37 | 56 | case 'deepEqual_primitiveOnly': { | |
| 38 | 57 | const values = array.map((_, i) => `str_${i}`); | |
| 39 | - benchmark(strict ? deepStrictEqual : deepEqual, n, values); | ||
| 58 | + benchmark(strict ? deepStrictEqual : deepEqual, n, values, values, order); | ||
| 40 | 59 | break; | |
| 41 | 60 | } | |
| 42 | 61 | case 'deepEqual_objectOnly': { | |
| 43 | 62 | const values = array.map((_, i) => [`str_${i}`, null]); | |
| 44 | - benchmark(strict ? deepStrictEqual : deepEqual, n, values); | ||
| 63 | + benchmark(strict ? deepStrictEqual : deepEqual, n, values, values, order); | ||
| 45 | 64 | break; | |
| 46 | 65 | } | |
| 47 | 66 | case 'deepEqual_mixed': { | |
| 48 | 67 | const values = array.map((_, i) => { | |
| 49 | 68 | return i % 2 ? [`str_${i}`, null] : `str_${i}`; | |
| 50 | 69 | }); | |
| 51 | - benchmark(strict ? deepStrictEqual : deepEqual, n, values); | ||
| 70 | + benchmark(strict ? deepStrictEqual : deepEqual, n, values, values, order); | ||
| 52 | 71 | break; | |
| 53 | 72 | } | |
| 54 | 73 | case 'notDeepEqual_primitiveOnly': { | |
| 55 | 74 | const values = array.map((_, i) => `str_${i}`); | |
| 56 | 75 | const values2 = values.slice(0); | |
| 57 | 76 | values2[Math.floor(len / 2)] = 'w00t'; | |
| 58 | - benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2); | ||
| 77 | + benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2, order); | ||
| 59 | 78 | break; | |
| 60 | 79 | } | |
| 61 | 80 | case 'notDeepEqual_objectOnly': { | |
| 62 | 81 | const values = array.map((_, i) => [`str_${i}`, null]); | |
| 63 | 82 | const values2 = values.slice(0); | |
| 64 | 83 | values2[Math.floor(len / 2)] = ['w00t']; | |
| 65 | - benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2); | ||
| 84 | + benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2, order); | ||
| 66 | 85 | break; | |
| 67 | 86 | } | |
| 68 | 87 | case 'notDeepEqual_mixed': { | |
@@ -71,7 +90,7 @@ function main({ n, len, method, strict }) { | |||
| 71 | 90 | }); | |
| 72 | 91 | const values2 = values.slice(); | |
| 73 | 92 | values2[0] = 'w00t'; | |
| 74 | - benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2); | ||
| 93 | + benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2, order); | ||
| 75 | 94 | break; | |
| 76 | 95 | } | |
| 77 | 96 | default: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,7 +62,7 @@ function createSets(length, extraProps, depth = 0) { | |||
| 62 | 62 | number: i, | |
| 63 | 63 | }, | |
| 64 | 64 | ['array', 'with', 'values'], | |
| 65 | - !depth ? new Set([1, 2, { nested: i }]) : new Set(), | ||
| 65 | + !depth ? new Set([1, { nested: i }]) : new Set(), | ||
| 66 | 66 | !depth ? createSets(2, extraProps, depth + 1) : null, | |
| 67 | 67 | ])); | |
| 68 | 68 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments