UNPKG

sucrase

Version:

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

38 lines (37 loc) 1.29 kB
#!/usr/bin/env node import * as fs from 'fs'; import * as babel from 'babel-core'; // Use require rather than import to hack around missing type info. var buble = require('buble'); import * as sucrase from '../src/index'; import * as TypeScript from '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(); }