| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3248cdb commit a469ce5
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,40 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const bench = common.createBenchmark(main, { | ||
| 5 | + n: [1e3], | ||
| 6 | + len: [1e2], | ||
| 7 | + method: ['strict', 'nonstrict'] | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + function main(conf) { | ||
| 11 | + const n = +conf.n; | ||
| 12 | + const len = +conf.len; | ||
| 13 | + var i; | ||
| 14 | + | ||
| 15 | + const data = Buffer.allocUnsafe(len); | ||
| 16 | + const actual = Buffer.alloc(len); | ||
| 17 | + const expected = Buffer.alloc(len); | ||
| 18 | + data.copy(actual); | ||
| 19 | + data.copy(expected); | ||
| 20 | + | ||
| 21 | + switch (conf.method) { | ||
| 22 | + case 'strict': | ||
| 23 | + bench.start(); | ||
| 24 | + for (i = 0; i < n; ++i) { | ||
| 25 | + // eslint-disable-next-line no-restricted-properties | ||
| 26 | + assert.deepEqual(actual, expected); | ||
| 27 | + } | ||
| 28 | + bench.end(n); | ||
| 29 | + break; | ||
| 30 | + case 'nonstrict': | ||
| 31 | + bench.start(); | ||
| 32 | + for (i = 0; i < n; ++i) { | ||
| 33 | + assert.deepStrictEqual(actual, expected); | ||
| 34 | + } | ||
| 35 | + bench.end(n); | ||
| 36 | + break; | ||
| 37 | + default: | ||
| 38 | + throw new Error('Unsupported method'); | ||
| 39 | + } | ||
| 40 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - var common = require('../common.js'); | ||
| 3 | - var assert = require('assert'); | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | 4 | ||
| 5 | 5 | const primValues = { | |
| 6 | 6 | 'null': null, | |
@@ -13,29 +13,43 @@ const primValues = { | |||
| 13 | 13 | 'new-array': new Array([1, 2, 3]) | |
| 14 | 14 | }; | |
| 15 | 15 | ||
| 16 | - var bench = common.createBenchmark(main, { | ||
| 16 | + const bench = common.createBenchmark(main, { | ||
| 17 | 17 | prim: Object.keys(primValues), | |
| 18 | - n: [25] | ||
| 18 | + n: [25], | ||
| 19 | + len: [1e5], | ||
| 20 | + method: ['strict', 'nonstrict'] | ||
| 19 | 21 | }); | |
| 20 | 22 | ||
| 21 | 23 | function main(conf) { | |
| 22 | - var prim = primValues[conf.prim]; | ||
| 23 | - var n = +conf.n; | ||
| 24 | - var primArray; | ||
| 25 | - var primArrayCompare; | ||
| 26 | - var x; | ||
| 24 | + const prim = primValues[conf.prim]; | ||
| 25 | + const n = +conf.n; | ||
| 26 | + const len = +conf.len; | ||
| 27 | + const actual = []; | ||
| 28 | + const expected = []; | ||
| 29 | + var i; | ||
| 27 | 30 | ||
| 28 | - primArray = new Array(); | ||
| 29 | - primArrayCompare = new Array(); | ||
| 30 | - for (x = 0; x < (1e5); x++) { | ||
| 31 | - primArray.push(prim); | ||
| 32 | - primArrayCompare.push(prim); | ||
| 31 | + for (var x = 0; x < len; x++) { | ||
| 32 | + actual.push(prim); | ||
| 33 | + expected.push(prim); | ||
| 33 | 34 | } | |
| 34 | 35 | ||
| 35 | - bench.start(); | ||
| 36 | - for (x = 0; x < n; x++) { | ||
| 37 | - // eslint-disable-next-line no-restricted-properties | ||
| 38 | - assert.deepEqual(primArray, primArrayCompare); | ||
| 36 | + switch (conf.method) { | ||
| 37 | + case 'strict': | ||
| 38 | + bench.start(); | ||
| 39 | + for (i = 0; i < n; ++i) { | ||
| 40 | + // eslint-disable-next-line no-restricted-properties | ||
| 41 | + assert.deepEqual(actual, expected); | ||
| 42 | + } | ||
| 43 | + bench.end(n); | ||
| 44 | + break; | ||
| 45 | + case 'nonstrict': | ||
| 46 | + bench.start(); | ||
| 47 | + for (i = 0; i < n; ++i) { | ||
| 48 | + assert.deepStrictEqual(actual, expected); | ||
| 49 | + } | ||
| 50 | + bench.end(n); | ||
| 51 | + break; | ||
| 52 | + default: | ||
| 53 | + throw new Error('Unsupported method'); | ||
| 39 | 54 | } | |
| 40 | - bench.end(n); | ||
| 41 | 55 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - var common = require('../common.js'); | ||
| 3 | - var assert = require('assert'); | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | 4 | ||
| 5 | 5 | const primValues = { | |
| 6 | 6 | 'null': null, | |
@@ -13,22 +13,37 @@ const primValues = { | |||
| 13 | 13 | 'new-array': new Array([1, 2, 3]) | |
| 14 | 14 | }; | |
| 15 | 15 | ||
| 16 | - var bench = common.createBenchmark(main, { | ||
| 16 | + const bench = common.createBenchmark(main, { | ||
| 17 | 17 | prim: Object.keys(primValues), | |
| 18 | - n: [1e5] | ||
| 18 | + n: [1e6], | ||
| 19 | + method: ['strict', 'nonstrict'] | ||
| 19 | 20 | }); | |
| 20 | 21 | ||
| 21 | 22 | function main(conf) { | |
| 22 | - var prim = primValues[conf.prim]; | ||
| 23 | - var n = +conf.n; | ||
| 24 | - var x; | ||
| 23 | + const prim = primValues[conf.prim]; | ||
| 24 | + const n = +conf.n; | ||
| 25 | + const actual = prim; | ||
| 26 | + const expected = prim; | ||
| 27 | + var i; | ||
| 25 | 28 | ||
| 26 | - bench.start(); | ||
| 27 | - | ||
| 28 | - for (x = 0; x < n; x++) { | ||
| 29 | - // eslint-disable-next-line no-restricted-properties | ||
| 30 | - assert.deepEqual(new Array([prim]), new Array([prim])); | ||
| 29 | + // Creates new array to avoid loop invariant code motion | ||
| 30 | + switch (conf.method) { | ||
| 31 | + case 'strict': | ||
| 32 | + bench.start(); | ||
| 33 | + for (i = 0; i < n; ++i) { | ||
| 34 | + // eslint-disable-next-line no-restricted-properties | ||
| 35 | + assert.deepEqual([actual], [expected]); | ||
| 36 | + } | ||
| 37 | + bench.end(n); | ||
| 38 | + break; | ||
| 39 | + case 'nonstrict': | ||
| 40 | + bench.start(); | ||
| 41 | + for (i = 0; i < n; ++i) { | ||
| 42 | + assert.deepStrictEqual([actual], [expected]); | ||
| 43 | + } | ||
| 44 | + bench.end(n); | ||
| 45 | + break; | ||
| 46 | + default: | ||
| 47 | + throw new Error('Unsupported method'); | ||
| 31 | 48 | } | |
| 32 | - | ||
| 33 | - bench.end(n); | ||
| 34 | 49 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,23 +1,41 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - var common = require('../common.js'); | ||
| 3 | - var assert = require('assert'); | ||
| 4 | - var bench = common.createBenchmark(main, { | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const bench = common.createBenchmark(main, { | ||
| 5 | 5 | type: ('Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array ' + | |
| 6 | 6 | 'Float32Array Float64Array Uint8ClampedArray').split(' '), | |
| 7 | - n: [1] | ||
| 7 | + n: [1], | ||
| 8 | + method: ['strict', 'nonstrict'], | ||
| 9 | + len: [1e6] | ||
| 8 | 10 | }); | |
| 9 | 11 | ||
| 10 | 12 | function main(conf) { | |
| 11 | - var type = conf.type; | ||
| 12 | - var clazz = global[type]; | ||
| 13 | - var n = +conf.n; | ||
| 13 | + const type = conf.type; | ||
| 14 | + const clazz = global[type]; | ||
| 15 | + const n = +conf.n; | ||
| 16 | + const len = +conf.len; | ||
| 14 | 17 | ||
| 15 | - bench.start(); | ||
| 16 | - var actual = new clazz(n * 1e6); | ||
| 17 | - var expected = new clazz(n * 1e6); | ||
| 18 | + const actual = new clazz(len); | ||
| 19 | + const expected = new clazz(len); | ||
| 20 | + var i; | ||
| 18 | 21 | ||
| 19 | - // eslint-disable-next-line no-restricted-properties | ||
| 20 | - assert.deepEqual(actual, expected); | ||
| 21 | - | ||
| 22 | - bench.end(n); | ||
| 22 | + switch (conf.method) { | ||
| 23 | + case 'strict': | ||
| 24 | + bench.start(); | ||
| 25 | + for (i = 0; i < n; ++i) { | ||
| 26 | + // eslint-disable-next-line no-restricted-properties | ||
| 27 | + assert.deepEqual(actual, expected); | ||
| 28 | + } | ||
| 29 | + bench.end(n); | ||
| 30 | + break; | ||
| 31 | + case 'nonstrict': | ||
| 32 | + bench.start(); | ||
| 33 | + for (i = 0; i < n; ++i) { | ||
| 34 | + assert.deepStrictEqual(actual, expected); | ||
| 35 | + } | ||
| 36 | + bench.end(n); | ||
| 37 | + break; | ||
| 38 | + default: | ||
| 39 | + throw new Error('Unsupported method'); | ||
| 40 | + } | ||
| 23 | 41 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments