| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 268a1ff commit b3c1c6f
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,39 +1,62 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common.js'); | |
| 3 | 3 | const assert = require('assert'); | |
| 4 | + | ||
| 4 | 5 | const bench = common.createBenchmark(main, { | |
| 5 | - n: [1e3], | ||
| 6 | - len: [1e2], | ||
| 7 | - method: ['strict', 'nonstrict'] | ||
| 6 | + n: [1e5], | ||
| 7 | + len: [1e2, 1e4], | ||
| 8 | + method: [ | ||
| 9 | + 'deepEqual', | ||
| 10 | + 'deepStrictEqual', | ||
| 11 | + 'notDeepEqual', | ||
| 12 | + 'notDeepStrictEqual' | ||
| 13 | + ] | ||
| 8 | 14 | }); | |
| 9 | 15 | ||
| 10 | 16 | function main(conf) { | |
| 11 | 17 | const n = +conf.n; | |
| 12 | 18 | const len = +conf.len; | |
| 13 | 19 | var i; | |
| 14 | 20 | ||
| 15 | - const data = Buffer.allocUnsafe(len); | ||
| 21 | + const data = Buffer.allocUnsafe(len + 1); | ||
| 16 | 22 | const actual = Buffer.alloc(len); | |
| 17 | 23 | const expected = Buffer.alloc(len); | |
| 24 | + const expectedWrong = Buffer.alloc(len + 1); | ||
| 18 | 25 | data.copy(actual); | |
| 19 | 26 | data.copy(expected); | |
| 27 | + data.copy(expectedWrong); | ||
| 20 | 28 | ||
| 21 | 29 | switch (conf.method) { | |
| 22 | - case 'strict': | ||
| 30 | + case 'deepEqual': | ||
| 23 | 31 | bench.start(); | |
| 24 | 32 | for (i = 0; i < n; ++i) { | |
| 25 | 33 | // eslint-disable-next-line no-restricted-properties | |
| 26 | 34 | assert.deepEqual(actual, expected); | |
| 27 | 35 | } | |
| 28 | 36 | bench.end(n); | |
| 29 | 37 | break; | |
| 30 | - case 'nonstrict': | ||
| 38 | + case 'deepStrictEqual': | ||
| 31 | 39 | bench.start(); | |
| 32 | 40 | for (i = 0; i < n; ++i) { | |
| 33 | 41 | assert.deepStrictEqual(actual, expected); | |
| 34 | 42 | } | |
| 35 | 43 | bench.end(n); | |
| 36 | 44 | break; | |
| 45 | + case 'notDeepEqual': | ||
| 46 | + bench.start(); | ||
| 47 | + for (i = 0; i < n; ++i) { | ||
| 48 | + // eslint-disable-next-line no-restricted-properties | ||
| 49 | + assert.notDeepEqual(actual, expectedWrong); | ||
| 50 | + } | ||
| 51 | + bench.end(n); | ||
| 52 | + break; | ||
| 53 | + case 'notDeepStrictEqual': | ||
| 54 | + bench.start(); | ||
| 55 | + for (i = 0; i < n; ++i) { | ||
| 56 | + assert.notDeepStrictEqual(actual, expectedWrong); | ||
| 57 | + } | ||
| 58 | + bench.end(n); | ||
| 59 | + break; | ||
| 37 | 60 | default: | |
| 38 | 61 | throw new Error('Unsupported method'); | |
| 39 | 62 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,73 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const bench = common.createBenchmark(main, { | ||
| 7 | + n: [1e6], | ||
| 8 | + size: [1e2, 1e3, 1e4], | ||
| 9 | + method: [ | ||
| 10 | + 'deepEqual', | ||
| 11 | + 'deepStrictEqual', | ||
| 12 | + 'notDeepEqual', | ||
| 13 | + 'notDeepStrictEqual' | ||
| 14 | + ] | ||
| 15 | + }); | ||
| 16 | + | ||
| 17 | + function createObj(source, add = '') { | ||
| 18 | + return source.map((n) => ({ | ||
| 19 | + foo: 'yarp', | ||
| 20 | + nope: { | ||
| 21 | + bar: `123${add}`, | ||
| 22 | + a: [1, 2, 3], | ||
| 23 | + baz: n | ||
| 24 | + } | ||
| 25 | + })); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + function main(conf) { | ||
| 29 | + const size = +conf.size; | ||
| 30 | + // TODO: Fix this "hack" | ||
| 31 | + const n = (+conf.n) / size; | ||
| 32 | + var i; | ||
| 33 | + | ||
| 34 | + const source = Array.apply(null, Array(size)); | ||
| 35 | + const actual = createObj(source); | ||
| 36 | + const expected = createObj(source); | ||
| 37 | + const expectedWrong = createObj(source, '4'); | ||
| 38 | + | ||
| 39 | + switch (conf.method) { | ||
| 40 | + case 'deepEqual': | ||
| 41 | + bench.start(); | ||
| 42 | + for (i = 0; i < n; ++i) { | ||
| 43 | + // eslint-disable-next-line no-restricted-properties | ||
| 44 | + assert.deepEqual(actual, expected); | ||
| 45 | + } | ||
| 46 | + bench.end(n); | ||
| 47 | + break; | ||
| 48 | + case 'deepStrictEqual': | ||
| 49 | + bench.start(); | ||
| 50 | + for (i = 0; i < n; ++i) { | ||
| 51 | + assert.deepStrictEqual(actual, expected); | ||
| 52 | + } | ||
| 53 | + bench.end(n); | ||
| 54 | + break; | ||
| 55 | + case 'notDeepEqual': | ||
| 56 | + bench.start(); | ||
| 57 | + for (i = 0; i < n; ++i) { | ||
| 58 | + // eslint-disable-next-line no-restricted-properties | ||
| 59 | + assert.notDeepEqual(actual, expectedWrong); | ||
| 60 | + } | ||
| 61 | + bench.end(n); | ||
| 62 | + break; | ||
| 63 | + case 'notDeepStrictEqual': | ||
| 64 | + bench.start(); | ||
| 65 | + for (i = 0; i < n; ++i) { | ||
| 66 | + assert.notDeepStrictEqual(actual, expectedWrong); | ||
| 67 | + } | ||
| 68 | + bench.end(n); | ||
| 69 | + break; | ||
| 70 | + default: | ||
| 71 | + throw new Error('Unsupported method'); | ||
| 72 | + } | ||
| 73 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,119 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const primValues = { | ||
| 7 | + 'null': null, | ||
| 8 | + 'undefined': undefined, | ||
| 9 | + 'string': 'a', | ||
| 10 | + 'number': 1, | ||
| 11 | + 'boolean': true, | ||
| 12 | + 'object': { 0: 'a' }, | ||
| 13 | + 'array': [1, 2, 3], | ||
| 14 | + 'new-array': new Array([1, 2, 3]) | ||
| 15 | + }; | ||
| 16 | + | ||
| 17 | + const bench = common.createBenchmark(main, { | ||
| 18 | + prim: Object.keys(primValues), | ||
| 19 | + n: [25], | ||
| 20 | + len: [1e5], | ||
| 21 | + method: [ | ||
| 22 | + 'deepEqual_Array', | ||
| 23 | + 'deepStrictEqual_Array', | ||
| 24 | + 'notDeepEqual_Array', | ||
| 25 | + 'notDeepStrictEqual_Array', | ||
| 26 | + 'deepEqual_Set', | ||
| 27 | + 'deepStrictEqual_Set', | ||
| 28 | + 'notDeepEqual_Set', | ||
| 29 | + 'notDeepStrictEqual_Set' | ||
| 30 | + ] | ||
| 31 | + }); | ||
| 32 | + | ||
| 33 | + function main(conf) { | ||
| 34 | + const prim = primValues[conf.prim]; | ||
| 35 | + const n = +conf.n; | ||
| 36 | + const len = +conf.len; | ||
| 37 | + const actual = []; | ||
| 38 | + const expected = []; | ||
| 39 | + const expectedWrong = []; | ||
| 40 | + var i; | ||
| 41 | + | ||
| 42 | + for (var x = 0; x < len; x++) { | ||
| 43 | + actual.push(prim); | ||
| 44 | + expected.push(prim); | ||
| 45 | + expectedWrong.push(prim); | ||
| 46 | + } | ||
| 47 | + expectedWrong.pop(); | ||
| 48 | + expectedWrong.push('b'); | ||
| 49 | + | ||
| 50 | + // Note: primitives are only added once to a set | ||
| 51 | + const actualSet = new Set(actual); | ||
| 52 | + const expectedSet = new Set(expected); | ||
| 53 | + const expectedWrongSet = new Set(expectedWrong); | ||
| 54 | + | ||
| 55 | + switch (conf.method) { | ||
| 56 | + case 'deepEqual_Array': | ||
| 57 | + bench.start(); | ||
| 58 | + for (i = 0; i < n; ++i) { | ||
| 59 | + // eslint-disable-next-line no-restricted-properties | ||
| 60 | + assert.deepEqual(actual, expected); | ||
| 61 | + } | ||
| 62 | + bench.end(n); | ||
| 63 | + break; | ||
| 64 | + case 'deepStrictEqual_Array': | ||
| 65 | + bench.start(); | ||
| 66 | + for (i = 0; i < n; ++i) { | ||
| 67 | + assert.deepStrictEqual(actual, expected); | ||
| 68 | + } | ||
| 69 | + bench.end(n); | ||
| 70 | + break; | ||
| 71 | + case 'notDeepEqual_Array': | ||
| 72 | + bench.start(); | ||
| 73 | + for (i = 0; i < n; ++i) { | ||
| 74 | + // eslint-disable-next-line no-restricted-properties | ||
| 75 | + assert.notDeepEqual(actual, expectedWrong); | ||
| 76 | + } | ||
| 77 | + bench.end(n); | ||
| 78 | + break; | ||
| 79 | + case 'notDeepStrictEqual_Array': | ||
| 80 | + bench.start(); | ||
| 81 | + for (i = 0; i < n; ++i) { | ||
| 82 | + assert.notDeepStrictEqual(actual, expectedWrong); | ||
| 83 | + } | ||
| 84 | + bench.end(n); | ||
| 85 | + break; | ||
| 86 | + case 'deepEqual_Set': | ||
| 87 | + bench.start(); | ||
| 88 | + for (i = 0; i < n; ++i) { | ||
| 89 | + // eslint-disable-next-line no-restricted-properties | ||
| 90 | + assert.deepEqual(actualSet, expectedSet); | ||
| 91 | + } | ||
| 92 | + bench.end(n); | ||
| 93 | + break; | ||
| 94 | + case 'deepStrictEqual_Set': | ||
| 95 | + bench.start(); | ||
| 96 | + for (i = 0; i < n; ++i) { | ||
| 97 | + assert.deepStrictEqual(actualSet, expectedSet); | ||
| 98 | + } | ||
| 99 | + bench.end(n); | ||
| 100 | + break; | ||
| 101 | + case 'notDeepEqual_Set': | ||
| 102 | + bench.start(); | ||
| 103 | + for (i = 0; i < n; ++i) { | ||
| 104 | + // eslint-disable-next-line no-restricted-properties | ||
| 105 | + assert.notDeepEqual(actualSet, expectedWrongSet); | ||
| 106 | + } | ||
| 107 | + bench.end(n); | ||
| 108 | + break; | ||
| 109 | + case 'notDeepStrictEqual_Set': | ||
| 110 | + bench.start(); | ||
| 111 | + for (i = 0; i < n; ++i) { | ||
| 112 | + assert.notDeepStrictEqual(actualSet, expectedWrongSet); | ||
| 113 | + } | ||
| 114 | + bench.end(n); | ||
| 115 | + break; | ||
| 116 | + default: | ||
| 117 | + throw new Error('Unsupported method'); | ||
| 118 | + } | ||
| 119 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,33 +16,54 @@ const primValues = { | |||
| 16 | 16 | const bench = common.createBenchmark(main, { | |
| 17 | 17 | prim: Object.keys(primValues), | |
| 18 | 18 | n: [1e6], | |
| 19 | - method: ['strict', 'nonstrict'] | ||
| 19 | + method: [ | ||
| 20 | + 'deepEqual', | ||
| 21 | + 'deepStrictEqual', | ||
| 22 | + 'notDeepEqual', | ||
| 23 | + 'notDeepStrictEqual' | ||
| 24 | + ] | ||
| 20 | 25 | }); | |
| 21 | 26 | ||
| 22 | 27 | function main(conf) { | |
| 23 | 28 | const prim = primValues[conf.prim]; | |
| 24 | 29 | const n = +conf.n; | |
| 25 | 30 | const actual = prim; | |
| 26 | 31 | const expected = prim; | |
| 32 | + const expectedWrong = 'b'; | ||
| 27 | 33 | var i; | |
| 28 | 34 | ||
| 29 | 35 | // Creates new array to avoid loop invariant code motion | |
| 30 | 36 | switch (conf.method) { | |
| 31 | - case 'strict': | ||
| 37 | + case 'deepEqual': | ||
| 32 | 38 | bench.start(); | |
| 33 | 39 | for (i = 0; i < n; ++i) { | |
| 34 | 40 | // eslint-disable-next-line no-restricted-properties | |
| 35 | 41 | assert.deepEqual([actual], [expected]); | |
| 36 | 42 | } | |
| 37 | 43 | bench.end(n); | |
| 38 | 44 | break; | |
| 39 | - case 'nonstrict': | ||
| 45 | + case 'deepStrictEqual': | ||
| 40 | 46 | bench.start(); | |
| 41 | 47 | for (i = 0; i < n; ++i) { | |
| 42 | 48 | assert.deepStrictEqual([actual], [expected]); | |
| 43 | 49 | } | |
| 44 | 50 | bench.end(n); | |
| 45 | 51 | break; | |
| 52 | + case 'notDeepEqual': | ||
| 53 | + bench.start(); | ||
| 54 | + for (i = 0; i < n; ++i) { | ||
| 55 | + // eslint-disable-next-line no-restricted-properties | ||
| 56 | + assert.notDeepEqual([actual], [expectedWrong]); | ||
| 57 | + } | ||
| 58 | + bench.end(n); | ||
| 59 | + break; | ||
| 60 | + case 'notDeepStrictEqual': | ||
| 61 | + bench.start(); | ||
| 62 | + for (i = 0; i < n; ++i) { | ||
| 63 | + assert.notDeepStrictEqual([actual], [expectedWrong]); | ||
| 64 | + } | ||
| 65 | + bench.end(n); | ||
| 66 | + break; | ||
| 46 | 67 | default: | |
| 47 | 68 | throw new Error('Unsupported method'); | |
| 48 | 69 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments