Skip to content

Conversation

@hyperz111
Copy link
Contributor

@hyperz111 hyperz111 commented Dec 7, 2025

Benchmark file:

import Benchmark from "benchmark";
import postcssJs from "postcss-js";
import postcssJs2 from "../postcss-js/index.mjs";

const suite = new Benchmark.Suite();
const style = {
  top: 10,
  '&:hover': {
    top: 5
  }
};

suite
        .add("postcss-js", () => postcssJs.parse(style))
        .add("postcss-js (fast dashify)", () => postcssJs2.parse(style))
        .on("cycle", function (event) {
                console.log(String(event.target));
        })
        .on("complete", function () {
                console.log("Fastest is " + this.filter("fastest").map("name"));
        })
        .run({ async: true });

Benchmark result:

postcss-js x 113,757 ops/sec ±0.58% (58 runs sampled)
postcss-js (fast dashify) x 178,389 ops/sec ±1.86% (60 runs sampled)

@hyperz111 hyperz111 changed the title chore: use fast dashify function in parser.js perf: use fast dashify function in parser.js Dec 7, 2025
@ai
Copy link
Member

ai commented Dec 8, 2025

Wow, great result.

@ai
Copy link
Member

ai commented Dec 8, 2025

I will merge and release it during this week

@hyperz111
Copy link
Contributor Author

@ai, can you try benchmark it yourself?

@ai ai merged commit e2654fb into postcss:main Dec 8, 2025
3 checks passed
@ai
Copy link
Member

ai commented Dec 8, 2025

My results:

postcss-js x 3,467,532 ops/sec ±3.65% (84 runs sampled)
postcss-js (fast dashify) x 3,670,041 ops/sec ±0.87% (88 runs sampled)
Fastest is postcss-js (fast dashify)

But hostly, you are using very simple input CSS. Proper benchmark should use more realistic example (try Bootstrap CSS as we do in PostCSS benchmark).

@ai
Copy link
Member

ai commented Dec 8, 2025

Thanks. Your fix was released in 5.0.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants