Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into support-cjs-esm
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Jul 9, 2020
2 parents 3833a2f + 1563d5e commit c404c98
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 105 deletions.
50 changes: 0 additions & 50 deletions buildTypes.js

This file was deleted.

9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,11 @@
},
"module": "lib/esm/pure-rand.js",
"types": "lib/types/pure-rand.d.ts",
"typesVersions": {
">=3.2": {
"*": [
"lib/ts3.2/pure-rand.d.ts"
]
}
},
"sideEffects": false,
"scripts": {
"format:check": "prettier --list-different \"**/*.{js,ts}\"",
"format:fix": "prettier --write \"**/*.{js,ts}\"",
"build": "tsc && tsc -p ./tsconfig.declaration.json && node ./buildTypes.js",
"build": "tsc && tsc -p ./tsconfig.declaration.json",
"build:esm": "tsc --module es2015 --outDir lib/esm --moduleResolution node && cp package.esm-template.json lib/esm/package.json",
"build:prod": "yarn build && yarn build:esm && node postbuild/main.cjs",
"test": "jest --config jest.config.js --coverage",
Expand Down
61 changes: 36 additions & 25 deletions perf/profiler.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
// @ts-check
// This file is a sample snippet to run a profiler on
// Run it:
// $: tsc --target es6
// $: node --prof --no-logfile-per-isolate perf/profiler.cjs
// $: node --prof-process v8.log > v8.out
const { genFor } = require('./helpers.cjs');
const { testGenerateWithSameDistribution, testGenerateWithSkipDistribution } = require('./tasks.cjs');
const prand = require('../lib/pure-rand');

const NUM_TESTS = 10000000;
const PROF_TYPE = process.env.PROF_TYPE || 'skip';
const PROF_GEN = process.env.PROF_GEN || 'congruential32';
console.log(`Profiler type: ${PROF_TYPE}`);
console.log(`Generator....: ${PROF_GEN}`);

const g = genFor(prand, PROF_GEN);
switch (PROF_TYPE) {
case 'same':
testGenerateWithSameDistribution(prand, g, NUM_TESTS);
break;
case 'skip':
testGenerateWithSkipDistribution(prand, g, NUM_TESTS);
break;
}
// @ts-check
// This file is a sample snippet to run a profiler on
// Run it:
// $: tsc --target es6
// $: PROF_TYPE=next PROF_GEN=xoroshiro128plus node --prof --no-logfile-per-isolate --trace-deopt --trace-opt-verbose perf/profiler.cjs
// $: node --prof-process v8.log > v8.out
const { genFor } = require('./helpers.cjs');
const {
testNext,
testJump,
testGenerateWithSameDistribution,
testGenerateWithSkipDistribution,
} = require('./tasks.cjs');
const prand = require('../lib/pure-rand');

const NUM_TESTS = 10000000;
const PROF_TYPE = process.env.PROF_TYPE || 'skip';
const PROF_GEN = process.env.PROF_GEN || 'congruential32';
console.log(`Profiler type: ${PROF_TYPE}`);
console.log(`Generator....: ${PROF_GEN}`);

const g = genFor(prand, PROF_GEN);
switch (PROF_TYPE) {
case 'next':
testNext(g, NUM_TESTS);
break;
case 'jump':
testJump(g, NUM_TESTS);
break;
case 'same':
testGenerateWithSameDistribution(prand, g, NUM_TESTS);
break;
case 'skip':
testGenerateWithSkipDistribution(prand, g, NUM_TESTS);
break;
}
60 changes: 38 additions & 22 deletions perf/tasks.cjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
// @ts-check

// Avoid the construction of an intermediate distribution
exports.testGenerateWithSkipDistributionSingle = (lib, g) => {
return lib.uniformIntDistribution(0, 0xffffffff, g)[1];
};
exports.testGenerateWithSkipDistribution = (lib, g, NUM_TESTS) => {
for (let idx = 0; idx !== NUM_TESTS; ++idx) {
g = exports.testGenerateWithSkipDistributionSingle(lib, g);
}
return g;
};

// Build the distribution once
// then generate multiple values using it
exports.testGenerateWithSameDistribution = (lib, g, NUM_TESTS) => {
const dist = lib.uniformIntDistribution(0, 0xffffffff);
for (let idx = 0; idx !== NUM_TESTS; ++idx) {
g = dist(g)[1];
}
return g;
};
// @ts-check

// Call next multiple times on the passed generator
exports.testNext = (g, NUM_TESTS) => {
for (let idx = 0; idx !== NUM_TESTS; ++idx) {
g = g.next()[1];
}
return g;
};

// Cell jump multiple times on the passed generator
exports.testJump = (g, NUM_TESTS) => {
for (let idx = 0; idx !== NUM_TESTS; ++idx) {
g = g.jump();
}
return g;
};

// Avoid the construction of an intermediate distribution
exports.testGenerateWithSkipDistributionSingle = (lib, g) => {
return lib.uniformIntDistribution(0, 0xffffffff, g)[1];
};
exports.testGenerateWithSkipDistribution = (lib, g, NUM_TESTS) => {
for (let idx = 0; idx !== NUM_TESTS; ++idx) {
g = exports.testGenerateWithSkipDistributionSingle(lib, g);
}
return g;
};

// Build the distribution once
// then generate multiple values using it
exports.testGenerateWithSameDistribution = (lib, g, NUM_TESTS) => {
const dist = lib.uniformIntDistribution(0, 0xffffffff);
for (let idx = 0; idx !== NUM_TESTS; ++idx) {
g = dist(g)[1];
}
return g;
};

0 comments on commit c404c98

Please sign in to comment.