Skip to content

Commit

Permalink
Added license and benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
w8r committed Jul 5, 2023
1 parent 6891122 commit 06f3ceb
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 11 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
37 changes: 35 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
```
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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",
Expand Down
26 changes: 22 additions & 4 deletions test/benchmark.js
Original file line number Diff line number Diff line change
@@ -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()
);
10 changes: 10 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

0 comments on commit 06f3ceb

Please sign in to comment.