| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 96530a4 commit 5016f75
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,41 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const tmpdir = require('../../test/common/tmpdir'); | ||
| 5 | + const fixtures = require('../../test/common/fixtures.js'); | ||
| 6 | + const fs = require('fs'); | ||
| 7 | + | ||
| 8 | + // This fixture has 2000+ exports. | ||
| 9 | + const fixtureFile = fixtures.path('snapshot', 'typescript.js'); | ||
| 10 | + // This is fixed - typescript.js is slow to load, so 10 is enough. | ||
| 11 | + // And we want to measure either 10 warm loads, or 1 cold load (but compare.js would run it many times) | ||
| 12 | + const runs = 10; | ||
| 13 | + const bench = common.createBenchmark(main, { | ||
| 14 | + type: ['cold', 'warm'], | ||
| 15 | + }, { | ||
| 16 | + setup() { | ||
| 17 | + tmpdir.refresh(); | ||
| 18 | + fs.cpSync(fixtureFile, tmpdir.resolve(`imported-cjs-initial.js`)); | ||
| 19 | + for (let i = 0; i < runs; i++) { | ||
| 20 | + fs.cpSync(fixtureFile, tmpdir.resolve(`imported-cjs-${i}.js`)); | ||
| 21 | + } | ||
| 22 | + }, | ||
| 23 | + }); | ||
| 24 | + | ||
| 25 | + async function main({ type }) { | ||
| 26 | + if (type === 'cold') { | ||
| 27 | + bench.start(); | ||
| 28 | + await import(tmpdir.fileURL(`imported-cjs-initial.js`)); | ||
| 29 | + bench.end(1); | ||
| 30 | + } else { | ||
| 31 | + await import(tmpdir.fileURL(`imported-cjs-initial.js`)); // Initialize the wasm first. | ||
| 32 | + bench.start(); | ||
| 33 | + let result; | ||
| 34 | + for (let i = 0; i < runs; i++) { | ||
| 35 | + result = await import(tmpdir.fileURL(`imported-cjs-${i}.js`)); | ||
| 36 | + } | ||
| 37 | + bench.end(runs); | ||
| 38 | + const mod = require(fixtures.path('snapshot', 'typescript.js')); | ||
| 39 | + assert.deepStrictEqual(Object.keys(mod), Object.keys(result.default)); | ||
| 40 | + } | ||
| 41 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments