chore: speed up space-only string check in lib/parser.js#2064
chore: speed up space-only string check in lib/parser.js#2064ai merged 2 commits intopostcss:mainfrom
Conversation
|
Interesting. Can you run https://github.com/postcss/benchmark to see the difference? |
I cannot run it. But you can try this. import Benchmark from "benchmark";
const suite = new Benchmark.Suite();
const name = " \t"
suite
.add("regex", function () {
/^\s*$/.test(name);
})
.add("!trim", function () {
!name.trim();
})
.on("cycle", function (event) {
console.log(String(event.target));
})
.on("complete", function () {
console.log("Fastest is " + this.filter("fastest").map("name"));
})
.run({ async: true }); |
What error do you have? Let’s fix it.
Isolated benchmarks will not tell how it affects overall performance. Sometimes better isolated results could be worse for overall performance (for instance, because of memory consumptions, etc). It optimizations it is critical rule to always run real use case benchmark. |
My device storage, i using a phone with 32GB storage with ±100mb left. But i have try my own benchmark for this. Code: import Benchmark from "benchmark";
import Input from "postcss/lib/input";
import Parser from "postcss/lib/parser";
import ParserNew from "../../gitclone/postcss/lib/parser.js";
import { readFileSync } from "fs";
const suite = new Benchmark.Suite();
const file = readFileSync("../../downloads/bootstrap.css", "utf8");
const input = new Input(file);
suite
.add("Current", function () {
new Parser(input).parse();
})
.add("New", function () {
new ParserNew(input).parse();
})
.on("cycle", function (event) {
console.log(String(event.target));
})
.on("complete", function () {
console.log("Fastest is " + this.filter("fastest").map("name"));
})
.run({ async: true });Result: $ node postcss-comment
Current x 9.96 ops/sec ±14.16% (24 runs sampled)
New x 11.43 ops/sec ±6.01% (24 runs sampled)
Fastest is New,Current
$ node postcss-comment
Current x 10.07 ops/sec ±14.08% (25 runs sampled)
New x 11.45 ops/sec ±9.09% (26 runs sampled)
Fastest is New
$ node postcss-comment
Current x 10.61 ops/sec ±14.03% (26 runs sampled)
New x 9.65 ops/sec ±12.49% (23 runs sampled)
Fastest is Current
$ node postcss-comment
Current x 10.14 ops/sec ±14.19% (25 runs sampled)
New x 11.91 ops/sec ±10.19% (28 runs sampled)
Fastest is New
$ node postcss-comment
Current x 10.70 ops/sec ±12.20% (25 runs sampled)
New x 10.18 ops/sec ±17.30% (25 runs sampled)
Fastest is Current,NewThis ONLY have a small speed different. |
|
Oh, i forgot to say this. NOT all dependencies in that benchmark repo is added in my |
|
Wow! You are hardcore developer. I will run benchmark, don't worry |
This code snippet:
is faster than: