UNPKG

sucrase

Version:

Super-fast alternative to Babel for when you can target modern JS runtimes

40 lines (39 loc) 1.36 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var fs = require("fs"); var babel = require("babel-core"); // Use require rather than import to hack around missing type info. var buble = require('buble'); var sucrase = require("../src/index"); var TypeScript = require("typescript"); function main() { console.log('Simulating transpilation of 100,000 lines of code:'); var code = fs.readFileSync('./benchmark/sample.js').toString(); runBenchmark('Sucrase', function () { return sucrase.transform(code); }); runBenchmark('Buble', function () { return buble.transform(code, { transforms: { modules: false } }); }); runBenchmark('TypeScript', function () { return TypeScript.transpileModule(code, { compilerOptions: { jsx: TypeScript.JsxEmit.React, target: TypeScript.ScriptTarget.ESNext } }); }); runBenchmark('Babel', function () { return babel.transform(code, { presets: ['react'] }); }); } function runBenchmark(name, runTrial) { // Run twice before starting the clock to warm up the JIT, caches, etc. runTrial(); runTrial(); console.time(name); for (var i = 0; i < 100; i++) { runTrial(); } console.timeEnd(name); } if (require.main === module) { main(); }