-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use mitata, esbuild for benchmarking speed and size (#86)
* use mitata, esbuild for benchmarking speed and size * move esbuild to bench job only * update nodejs version for bench job
- Loading branch information
1 parent
6a1eb72
commit 4c5e981
Showing
14 changed files
with
297 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { run, bench, group } from "mitata" | ||
import { buildSync } from "esbuild" | ||
import { createRequire } from "module" | ||
import { dirname } from "path" | ||
import { createContext, compileFunction } from "vm" | ||
|
||
let filename = new URL(import.meta.url).pathname | ||
|
||
function build(contents) { | ||
let root = dirname(filename) | ||
let result = buildSync({ | ||
bundle: true, | ||
write: false, | ||
platform: "node", | ||
stdin: { contents, loader: "js", resolveDir: root }, | ||
}) | ||
let code = result.outputFiles[0].text | ||
return code | ||
} | ||
|
||
function compile(code, context) { | ||
return compileFunction(code, [], { parsingContext: context }) | ||
} | ||
|
||
group(() => { | ||
let codeP = build(`let picocolors = require("../picocolors.js")`) | ||
let contextP = createContext({ require: createRequire(filename), process: { env: {} } }) | ||
bench("picocolors", () => compile(codeP, contextP)) | ||
|
||
let codeAC = build(`let ansi = require("ansi-colors")`) | ||
let contextAC = createContext({ require: createRequire(filename), process: { env: {} } }) | ||
bench("ansi-colors", () => compile(codeAC, contextAC)) | ||
|
||
let codeK = build(`let kleur = require("kleur")`) | ||
let contextK = createContext({ require: createRequire(filename), process: { env: {} } }) | ||
bench("kleur", () => compile(codeK, contextK)) | ||
|
||
let codeKC = build(`let kleurColors = require("kleur/colors")`) | ||
let contextKC = createContext({ require: createRequire(filename), process: { env: {} } }) | ||
bench("kleur/colors", () => compile(codeKC, contextKC)) | ||
|
||
let codeC = build(`let colorette = require("colorette")`) | ||
let contextC = createContext({ require: createRequire(filename), process: { env: {} } }) | ||
bench("colorette", () => compile(codeC, contextC)) | ||
|
||
let codeN = build(`let nanocolors = require("nanocolors")`) | ||
let contextN = createContext({ require: createRequire(filename), process: { env: {} } }) | ||
bench("nanocolors", () => compile(codeN, contextN)) | ||
|
||
let codeCh = build(`let chalk = require("chalk")`) | ||
let contextCh = createContext({ require: createRequire(filename), process: { env: {} } }) | ||
bench("chalk", () => compile(codeCh, contextCh)) | ||
|
||
let codeCC = build(`let cliColor = require("cli-color")`) | ||
let contextCC = createContext({ require: createRequire(filename), process: { env: {} } }) | ||
bench("cli-color", () => compile(codeCC, contextCC)) | ||
}) | ||
|
||
await run() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.