-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into support-cjs-esm
- Loading branch information
Showing
4 changed files
with
75 additions
and
105 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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; | ||
} |
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 |
---|---|---|
@@ -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; | ||
}; |