diff --git a/.github/workflows/ci-and-publish.yml b/.github/workflows/ci-and-publish.yml index 86ab67a..42bace1 100644 --- a/.github/workflows/ci-and-publish.yml +++ b/.github/workflows/ci-and-publish.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x, 18.x, 20.x] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} @@ -31,7 +31,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: 16 + node-version: 20 registry-url: https://registry.npmjs.org/ cache: npm - run: npm ci diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e31d6f9..2c19edb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x, 18.x, 20.x] steps: - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} diff --git a/README.md b/README.md index da43bb1..07cb59c 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Sources: [classix](https://deno.bundlejs.com?q=classix), [clsx](https://deno.bun ![Performance comparison chart](media/perf.png) -Sources: Ran [benchmark](benchmark/) on an AMD Ryzen 5 5600x. +Sources: Ran [benchmark](benchmark/) on an AMD Ryzen 5 5600x with Node 20. ## Highlights diff --git a/benchmark/index.mjs b/benchmark/index.mjs index 028a195..8e4d9d5 100644 --- a/benchmark/index.mjs +++ b/benchmark/index.mjs @@ -1,14 +1,69 @@ -import benchmark from "benchmark"; +import { performance } from "node:perf_hooks"; import classnames from "classnames"; import { clsx } from "clsx"; import { cx } from "classix"; import { cx as cxLocal } from "../dist/esm/classix.mjs"; -new benchmark.Suite() - .add("classnames", () => classnames("class1", true && "class2")) - .add("clsx", () => clsx("class1", true && "class2")) - .add("classix", () => cx("class1", true && "class2")) - .add("classix (local)", () => cxLocal("class1", true && "class2")) - .on("cycle", (event) => console.log(event.target.toString())) - .run(); +const NB_RUN = 100_000_000; + +function logResult(name, ms) { + const millionsOfOpsPerSecond = ((NB_RUN * 1000) / ms / 1_000_000).toFixed(1); + console.log(`${name}: ${millionsOfOpsPerSecond}M ops/s`); +} + +// Repetition of code was used as to not affect performance +let start = 0; +let stop = 0; + +start = performance.now(); +for (let i = 0; i < NB_RUN; i++) { + classnames("class-1", { "class-2": true }); +} +stop = performance.now(); +logResult("classnames (object)", stop - start); + +// + +start = performance.now(); +for (let i = 0; i < NB_RUN; i++) { + classnames("class-1", true && "class-2"); +} +stop = performance.now(); +logResult("classnames", stop - start); + +// + +start = performance.now(); +for (let i = 0; i < NB_RUN; i++) { + clsx("class-1", { "class-2": true }); +} +stop = performance.now(); +logResult("clsx (object)", stop - start); + +// + +start = performance.now(); +for (let i = 0; i < NB_RUN; i++) { + clsx("class-1", true && "class-2"); +} +stop = performance.now(); +logResult("clsx", stop - start); + +// + +start = performance.now(); +for (let i = 0; i < NB_RUN; i++) { + cx("class-1", true && "class-2"); +} +stop = performance.now(); +logResult("classix", stop - start); + +// + +start = performance.now(); +for (let i = 0; i < NB_RUN; i++) { + cxLocal("class-1", true && "class-2"); +} +stop = performance.now(); +logResult("classix (local)", stop - start); diff --git a/media/perf.png b/media/perf.png index 0235c31..d3111d6 100644 Binary files a/media/perf.png and b/media/perf.png differ diff --git a/package-lock.json b/package-lock.json index 259eea9..21054ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "@typescript-eslint/eslint-plugin": "^5.30.5", "@typescript-eslint/parser": "^5.30.5", "@vitest/coverage-c8": "^0.30.1", - "benchmark": "^2.1.4", "classix": "^2.1.8", "classnames": "^2.3.1", "clsx": "^1.2.1", @@ -1818,16 +1817,6 @@ "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", "dev": true }, - "node_modules/benchmark": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz", - "integrity": "sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ==", - "dev": true, - "dependencies": { - "lodash": "^4.17.4", - "platform": "^1.3.3" - } - }, "node_modules/binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -7590,12 +7579,6 @@ "pathe": "^1.1.0" } }, - "node_modules/platform": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", - "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", - "dev": true - }, "node_modules/postcss": { "version": "8.4.21", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", @@ -10596,16 +10579,6 @@ "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", "dev": true }, - "benchmark": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz", - "integrity": "sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ==", - "dev": true, - "requires": { - "lodash": "^4.17.4", - "platform": "^1.3.3" - } - }, "binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -14700,12 +14673,6 @@ "pathe": "^1.1.0" } }, - "platform": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", - "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", - "dev": true - }, "postcss": { "version": "8.4.21", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", diff --git a/package.json b/package.json index 2347a4f..77de6dc 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "@typescript-eslint/eslint-plugin": "^5.30.5", "@typescript-eslint/parser": "^5.30.5", "@vitest/coverage-c8": "^0.30.1", - "benchmark": "^2.1.4", "classix": "^2.1.8", "classnames": "^2.3.1", "clsx": "^1.2.1",