Skip to content

Commit

Permalink
fix: wrong benchmark setup
Browse files Browse the repository at this point in the history
  • Loading branch information
LongYinan committed Aug 23, 2020
1 parent aa888e7 commit 7bd298d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
const fs = require('fs')
const os = require('os')

const { transformSync: transformSyncNapi, transform: transformNapi } = require('@swc-node/core')
const { transformSync, transform } = require('@swc/core')
Expand All @@ -8,7 +9,6 @@ const chalk = require('chalk')
const { transformSync: transformSyncEsbuild, startService } = require('esbuild')
const ts = require('typescript')

const os = require('os')
const cpuCount = os.cpus().length

const syncSuite = new Suite('Transform rxjs/AjaxObservable.ts benchmark')
Expand Down Expand Up @@ -95,7 +95,7 @@ async function runAsync() {
name: '@swc-node/core',
fn: (deferred) => {
Promise.all(
new Array(cpuCount).map(() => {
Array.from({ length: cpuCount }).map(() => {
return transformNapi(SOURCE_CODE, SOURCE_PATH, {
target: 'es2016',
module: 'commonjs',
Expand All @@ -118,7 +118,7 @@ async function runAsync() {
name: '@swc/core',
fn: (deferred) => {
Promise.all(
new Array(cpuCount).map(() => {
Array.from({ length: cpuCount }).map(() => {
return transform(SOURCE_CODE, {
filename: SOURCE_PATH,
jsc: {
Expand Down Expand Up @@ -148,15 +148,15 @@ async function runAsync() {
name: 'esbuild',
fn: (deferred) => {
Promise.all(
new Array(cpuCount).map(() => {
Array.from({ length: cpuCount }).map(() =>
service.transform(SOURCE_CODE, {
sourcefile: SOURCE_PATH,
loader: 'ts',
sourcemap: true,
minify: false,
target: 'es2016',
})
}),
}),
),
).then(() => {
deferred.resolve()
})
Expand All @@ -166,6 +166,7 @@ async function runAsync() {
queued: true,
})
.on('cycle', function (event) {
event.target.hz = event.target.hz * cpuCount
console.info(String(event.target))
})
.on('complete', function () {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
type: opts.module || 'commonjs',
},
sourceMaps: typeof opts.sourcemap === 'undefined' ? true : opts.sourcemap,
swcrc: false,
}
return bindings.transformSync(source, path, Buffer.from(JSON.stringify(swcOptions)))
},
Expand All @@ -61,6 +62,7 @@ module.exports = {
module: {
type: opts.module || 'commonjs',
},
swcrc: false,
sourceMaps: typeof opts.sourcemap === 'undefined' ? true : opts.sourcemap,
}
return bindings.transform(source, path, Buffer.from(JSON.stringify(swcOptions)))
Expand Down

0 comments on commit 7bd298d

Please sign in to comment.