From 06f3cebc8fa9681df08b54ba05893b14cfc0e81b Mon Sep 17 00:00:00 2001 From: Alexander Milevski Date: Wed, 5 Jul 2023 20:26:28 +0200 Subject: [PATCH] Added license and benchmarks --- LICENSE | 21 +++++++++++++++++++++ Readme.md | 37 +++++++++++++++++++++++++++++++++++-- package-lock.json | 1 - package.json | 13 +++++++++---- test/benchmark.js | 26 ++++++++++++++++++++++---- test/test.ts | 10 ++++++++++ 6 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f362ea7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Alexander Milevski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Readme.md b/Readme.md index b39e353..dc8481a 100644 --- a/Readme.md +++ b/Readme.md @@ -1,8 +1,8 @@ # `inline-functions` -This plugin allows you to inline functions in your code. This is useful for performance reasons, as it allows you to avoid function calls and instead inline the function body directly. +This library allows you to inline functions in your JS/TS code. This is useful for performance reasons, as it allows you to avoid function calls and instead inline the function body directly. -This plugin is a collection of plugins for different build systems. It is designed to be used with [`vite`](https://vitejs.dev), [`rollup`](https://rollupjs.org), and [`esbuild`](https://esbuild.github.io). +It comes as a collection of plugins for different build systems. It is designed to be used with [`vite`](https://vitejs.dev), [`rollup`](https://rollupjs.org), and [`esbuild`](https://esbuild.github.io). Inspired by the clever trick used in [`robust-predicates`](https://github.com/mourner/robust-predicates/blob/c20b0ab9ab4c4f2969f3611908c41ce76aa0e7a7/compile.js) by @mourner. @@ -146,3 +146,36 @@ export default { }; ``` + +### Examples + +See [`test`](./test) for examples and benchmarks. + +### Some benchmarks + +``` +Running "Vite" suite... +Progress: 100% + + Inlined: + 1 464 435 ops/s, ±4.63% | fastest + + Not inlined: + 1 187 396 ops/s, ±5.75% | slowest, 18.92% slower + +Running "Rollup" suite... + + Inlined: + 1 560 921 ops/s, ±1.27% | fastest + + Not inlined: + 1 302 231 ops/s, ±0.11% | slowest, 16.57% slower + +Running "esbuild" suite... + + Inlined: + 1 564 889 ops/s, ±0.80% | fastest + + Not inlined: + 1 281 501 ops/s, ±1.02% | slowest, 18.11% slower +``` diff --git a/package-lock.json b/package-lock.json index a2b24dc..0ae1761 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "devDependencies": { "@rollup/plugin-typescript": "^11.1.2", "@rollup/pluginutils": "^5.0.2", - "benchmark": "^2.1.4", "benny": "^3.7.1", "esbuild": "^0.17.19", "rollup": "^3.26.1", diff --git a/package.json b/package.json index 49feb5f..03c0e10 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "inline-functions", "version": "0.0.1", - "description": "", + "description": "This library allows you to inline functions in your JS/TS code. This is useful for performance reasons, as it allows you to avoid function calls and instead inline the function body directly. It provides plugins for Vite, Rollup and esbuild.", "type": "module", "files": [ "dist" @@ -56,13 +56,18 @@ "rollup": "^3.26.1", "vite": "^4.3.9" }, - "keywords": [], + "keywords": [ + "performance", + "inline", + "vite", + "rollup", + "esbuild" + ], "author": "", - "license": "ISC", + "license": "MIT", "devDependencies": { "@rollup/plugin-typescript": "^11.1.2", "@rollup/pluginutils": "^5.0.2", - "benchmark": "^2.1.4", "benny": "^3.7.1", "esbuild": "^0.17.19", "rollup": "^3.26.1", diff --git a/test/benchmark.js b/test/benchmark.js index 9f79cd5..14bda31 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -1,10 +1,28 @@ import bench from "benny"; -import { inlined, notInlined } from "./dist/esbuild.js"; +import * as rollup from "./dist/rollup.js"; +import * as esbuild from "./dist/esbuild.js"; +import * as vite from "./dist/vite.js"; bench.suite( - "My suite", - bench.add("Inlined", inlined), - bench.add("Not inlined", notInlined), + "Vite", + bench.add("Inlined", vite.inlined), + bench.add("Not inlined", vite.notInlined), + bench.cycle(), + bench.complete() +); + +bench.suite( + "Rollup", + bench.add("Inlined", rollup.inlined), + bench.add("Not inlined", rollup.notInlined), + bench.cycle(), + bench.complete() +); + +bench.suite( + "esbuild", + bench.add("Inlined", esbuild.inlined), + bench.add("Not inlined", esbuild.notInlined), bench.cycle(), bench.complete() ); diff --git a/test/test.ts b/test/test.ts index 0d30735..c12eb24 100644 --- a/test/test.ts +++ b/test/test.ts @@ -33,6 +33,11 @@ export function inlined() { crossProduct(foo, bar, baz); } + for (let i = 0; i < 100; i++) { + crossProduct(foo, bar, baz); + add(baz, bar); + } + return foo; } @@ -48,5 +53,10 @@ export function notInlined() { crossProduct2(foo, bar, baz); } + for (let i = 0; i < 100; i++) { + crossProduct2(foo, bar, baz); + add2(baz, bar); + } + return foo; }