diff --git a/benchmark/babel.js b/benchmark/babel.js new file mode 100644 index 00000000..b5d1694a --- /dev/null +++ b/benchmark/babel.js @@ -0,0 +1,20 @@ +import {readFileSync} from 'fs' +import {resolve} from 'path' +import Benchmark from 'benchmark' +import {transform as babel} from 'babel-core' + +import plugin from '../src/babel' + +const read = path => readFileSync(resolve(__dirname, path), 'utf8') +const fixture = read('./fixtures/babel.js') + +module.exports = new Benchmark({ + name: 'Babel transform', + minSamples: 500, + fn: () => { + babel(fixture, { + babelrc: false, + plugins: [plugin] + }) + } +}) diff --git a/benchmark/fixtures/babel.js b/benchmark/fixtures/babel.js new file mode 100644 index 00000000..ebc929eb --- /dev/null +++ b/benchmark/fixtures/babel.js @@ -0,0 +1,38 @@ +export const Test1 = () => ( +
+ test + test +

+

+

+

+

+

+ + +
+) + +export const Test2 = () => test + +export default class { + render() { + return ( +
+

test

+ + + +
+ ) + } +} diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 29b49b84..70179287 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -5,6 +5,7 @@ import gulp from 'gulp' import babel from 'gulp-babel' import {transformFile} from 'babel-core' import size from 'human-size' +import benchmark from 'gulp-benchmark' gulp.task('transpile', () => { gulp.src('src/**/*.js') @@ -41,5 +42,13 @@ gulp.task('runtime-size', async () => { } }) -gulp.task('watch', () => gulp.watch('src/*', ['transpile'])) +gulp.task('benchmark', () => { + gulp.src('*.js', {read: false, cwd: './benchmark'}) + .pipe(babel()) + .pipe(benchmark()) +}) +gulp.task('watch', () => { + gulp.watch('src/*', ['transpile']) + gulp.watch('benchmark/*.js', ['benchmark']) +}) gulp.task('default', ['transpile', 'watch']) diff --git a/package.json b/package.json index 5ed47e3c..d8bad72d 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,10 @@ "babel-preset-react": "^6.16.0", "babel-preset-stage-3": "^6.16.0", "babel-register": "^6.18.0", + "benchmark": "^2.1.3", "gulp": "^3.9.1", "gulp-babel": "^6.1.2", + "gulp-benchmark": "^1.1.1", "human-size": "^1.1.0", "mz": "^2.6.0", "react": "^15.4.1",