Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce package size by removing semi #28

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions benchmarks/complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
// 2. Run tests 5 times.
// 3. Took the best result for each candidate.

let benchmark = require("benchmark");
let colorette = require("colorette");
let kleur = require("kleur");
let kleurColors = require("kleur/colors");
let chalk = require("chalk");
let ansi = require("ansi-colors");
let cliColor = require("cli-color");
let picocolors = require("../picocolors.js");
let nanocolors = require("nanocolors");
let benchmark = require("benchmark")
let colorette = require("colorette")
let kleur = require("kleur")
let kleurColors = require("kleur/colors")
let chalk = require("chalk")
let ansi = require("ansi-colors")
let cliColor = require("cli-color")
let picocolors = require("../picocolors.js")
let nanocolors = require("nanocolors")

function formatNumber(number) {
return String(number)
.replace(/\d{3}$/, ",$&")
.replace(/^(\d|\d\d)(\d{3},)/, "$1,$2");
.replace(/^(\d|\d\d)(\d{3},)/, "$1,$2")
}

let suite = new benchmark.Suite();
let out;
let suite = new benchmark.Suite()
let out

let index = 1e8;
let index = 1e8

suite
.add("chalk", () => {
out =
chalk.bgRed.black(" ERROR ") +
chalk.red(
" Add plugin " + chalk.yellow("name") + " to use time limit with " + chalk.yellow(++index)
);
)
})
.add("cli-color", () => {
out =
Expand All @@ -42,21 +42,21 @@ suite
cliColor.yellow("name") +
" to use time limit with " +
cliColor.yellow(++index)
);
)
})
.add("ansi-colors", () => {
out =
ansi.bgRed.black(" ERROR ") +
ansi.red(
" Add plugin " + ansi.yellow("name") + " to use time limit with " + ansi.yellow(++index)
);
)
})
.add("kleur", () => {
out =
kleur.bgRed().black(" ERROR ") +
kleur.red(
" Add plugin " + kleur.yellow("name") + " to use time limit with " + kleur.yellow(++index)
);
)
})
.add("kleur/colors", () => {
out =
Expand All @@ -66,7 +66,7 @@ suite
kleurColors.yellow("name") +
" to use time limit with " +
kleurColors.yellow(++index)
);
)
})
.add("colorette", () => {
out =
Expand All @@ -76,7 +76,7 @@ suite
colorette.yellow("name") +
" to use time limit with " +
colorette.yellow(++index)
);
)
})
.add("nanocolors", () => {
out =
Expand All @@ -86,7 +86,7 @@ suite
nanocolors.yellow("name") +
" to use time limit with " +
nanocolors.yellow(++index)
);
)
})
.add("picocolors", () => {
out =
Expand All @@ -96,16 +96,16 @@ suite
picocolors.yellow("name") +
" to use time limit with " +
picocolors.yellow(`${++index}`)
);
)
})
.on("cycle", (event) => {
let prefix = event.target.name === "picocolors" ? "+ " : " ";
let name = event.target.name.padEnd("kleur/colors ".length);
let hz = formatNumber(event.target.hz.toFixed(0)).padStart(10);
process.stdout.write(`${prefix}${name}${picocolors.bold(hz)} ops/sec\n`);
let prefix = event.target.name === "picocolors" ? "+ " : " "
let name = event.target.name.padEnd("kleur/colors ".length)
let hz = formatNumber(event.target.hz.toFixed(0)).padStart(10)
process.stdout.write(`${prefix}${name}${picocolors.bold(hz)} ops/sec\n`)
})
.on("error", (event) => {
process.stderr.write(picocolors.red(event.target.error.toString()) + "\n");
process.exit(1);
process.stderr.write(picocolors.red(event.target.error.toString()) + "\n")
process.exit(1)
})
.run();
.run()
56 changes: 28 additions & 28 deletions benchmarks/loading-runner.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
const { performance } = require("perf_hooks");
const { performance } = require("perf_hooks")

let before;
let before
function showTime(name) {
let after = performance.now();
process.stdout.write(name + " " + (after - before) + "\n");
let after = performance.now()
process.stdout.write(name + " " + (after - before) + "\n")
}

before = performance.now();
let chalk = require("chalk");
showTime("chalk");
before = performance.now()
let chalk = require("chalk")
showTime("chalk")

before = performance.now();
let cliColor = require("cli-color");
showTime("cli-color");
before = performance.now()
let cliColor = require("cli-color")
showTime("cli-color")

before = performance.now();
let ansi = require("ansi-colors");
showTime("ansi-colors");
before = performance.now()
let ansi = require("ansi-colors")
showTime("ansi-colors")

before = performance.now();
let kleur = require("kleur");
showTime("kleur");
before = performance.now()
let kleur = require("kleur")
showTime("kleur")

before = performance.now();
let kleurColors = require("kleur/colors");
showTime("kleur/colors");
before = performance.now()
let kleurColors = require("kleur/colors")
showTime("kleur/colors")

before = performance.now();
let colorette = require("colorette");
showTime("colorette");
before = performance.now()
let colorette = require("colorette")
showTime("colorette")

before = performance.now();
let nanocolors = require("nanocolors");
showTime("nanocolors");
before = performance.now()
let nanocolors = require("nanocolors")
showTime("nanocolors")

before = performance.now();
let picocolors = require("../picocolors.js");
showTime("picocolors");
before = performance.now()
let picocolors = require("../picocolors.js")
showTime("picocolors")
22 changes: 11 additions & 11 deletions benchmarks/loading.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#!/usr/bin/env node

let { execSync } = require("child_process");
let { execSync } = require("child_process")

let RUNS = 50;
let RUNS = 50

let results = {};
let results = {}

for (let i = 0; i < RUNS; i++) {
let output = execSync("node ./benchmarks/loading-runner.js").toString();
let output = execSync("node ./benchmarks/loading-runner.js").toString()
output
.trim()
.split("\n")
.forEach((line) => {
let [name, result] = line.split(" ");
results[name] = (results[name] || 0) + parseFloat(result);
});
let [name, result] = line.split(" ")
results[name] = (results[name] || 0) + parseFloat(result)
})
}

for (let name in results) {
let prefix = name === "picocolors" ? "+ " : " ";
let title = name.padEnd("kleur/colors ".length);
let prefix = name === "picocolors" ? "+ " : " "
let title = name.padEnd("kleur/colors ".length)
let time = (Math.round((1000 * results[name]) / RUNS) / 1000)
.toString()
.replace(/\.\d$/, "$&00")
.replace(/\.\d\d$/, "$&0");
process.stdout.write(prefix + title + "\x1B[1m" + time.padStart(6) + "\x1B[22m ms\n");
.replace(/\.\d\d$/, "$&0")
process.stdout.write(prefix + title + "\x1B[1m" + time.padStart(6) + "\x1B[22m ms\n")
}
68 changes: 34 additions & 34 deletions benchmarks/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,66 @@
// 2. Run tests 5 times.
// 3. Took the best result for each candidate.

let benchmark = require("benchmark");
let colorette = require("colorette");
let kleur = require("kleur");
let kleurColors = require("kleur/colors");
let chalk = require("chalk");
let ansi = require("ansi-colors");
let cliColor = require("cli-color");
let picocolors = require("../picocolors.js");
let nanocolors = require("nanocolors");
let benchmark = require("benchmark")
let colorette = require("colorette")
let kleur = require("kleur")
let kleurColors = require("kleur/colors")
let chalk = require("chalk")
let ansi = require("ansi-colors")
let cliColor = require("cli-color")
let picocolors = require("../picocolors.js")
let nanocolors = require("nanocolors")

function formatNumber(number) {
return String(number)
.replace(/\d{3}$/, ",$&")
.replace(/^(\d|\d\d)(\d{3},)/, "$1,$2");
.replace(/^(\d|\d\d)(\d{3},)/, "$1,$2")
}

console.log(colorette.green("colorette"));
console.log(kleur.green("kleur"));
console.log(chalk.green("chalk"));
console.log(ansi.green("ansi"));
console.log(cliColor.green("cliColor"));
console.log(picocolors.green("picocolors"));
console.log(nanocolors.green("nanocolors"));
console.log(colorette.green("colorette"))
console.log(kleur.green("kleur"))
console.log(chalk.green("chalk"))
console.log(ansi.green("ansi"))
console.log(cliColor.green("cliColor"))
console.log(picocolors.green("picocolors"))
console.log(nanocolors.green("nanocolors"))

let suite = new benchmark.Suite();
let out;
let suite = new benchmark.Suite()
let out

suite
.add("chalk", () => {
out = chalk.red("Add plugin to use time limit");
out = chalk.red("Add plugin to use time limit")
})
.add("cli-color", () => {
out = cliColor.red("Add plugin to use time limit");
out = cliColor.red("Add plugin to use time limit")
})
.add("ansi-colors", () => {
out = ansi.red("Add plugin to use time limit");
out = ansi.red("Add plugin to use time limit")
})
.add("kleur", () => {
out = kleur.red("Add plugin to use time limit");
out = kleur.red("Add plugin to use time limit")
})
.add("kleur/colors", () => {
out = kleurColors.red("Add plugin to use time limit");
out = kleurColors.red("Add plugin to use time limit")
})
.add("colorette", () => {
out = colorette.red("Add plugin to use time limit");
out = colorette.red("Add plugin to use time limit")
})
.add("nanocolors", () => {
out = nanocolors.red("Add plugin to use time limit");
out = nanocolors.red("Add plugin to use time limit")
})
.add("picocolors", () => {
out = picocolors.red("Add plugin to use time limit");
out = picocolors.red("Add plugin to use time limit")
})
.on("cycle", (event) => {
let prefix = event.target.name === "picocolors" ? "+ " : " ";
let name = event.target.name.padEnd("kleur/colors ".length);
let hz = formatNumber(event.target.hz.toFixed(0)).padStart(10);
process.stdout.write(`${prefix}${name}${picocolors.bold(hz)} ops/sec\n`);
let prefix = event.target.name === "picocolors" ? "+ " : " "
let name = event.target.name.padEnd("kleur/colors ".length)
let hz = formatNumber(event.target.hz.toFixed(0)).padStart(10)
process.stdout.write(`${prefix}${name}${picocolors.bold(hz)} ops/sec\n`)
})
.on("error", (event) => {
process.stderr.write(picocolors.red(event.target.error.toString()) + "\n");
process.exit(1);
process.stderr.write(picocolors.red(event.target.error.toString()) + "\n")
process.exit(1)
})
.run();
.run()
Loading