Skip to content

Commit 336206f

Browse files
authored
Merge pull request #16 from ilteoood/feat/benchmarks
Feat/benchmarks
2 parents eee3cff + faa6294 commit 336206f

File tree

7 files changed

+73
-7
lines changed

7 files changed

+73
-7
lines changed

.github/workflows/bechmark.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Benchmark workflow
2+
on: [push, pull_request]
3+
jobs:
4+
benchmark:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
node-version: [18.x, 20.x, 22.x]
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Use Node.js ${{ matrix.node-version }}
12+
uses: actions/setup-node@v4
13+
with:
14+
node-version: ${{ matrix.node-version }}
15+
- uses: pnpm/action-setup@v2
16+
with:
17+
version: latest
18+
- run: pnpm install --frozen-lockfile
19+
- run: pnpm run benchmark

benchmarks/map-filter-reduce.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, bench } from "vitest";
2+
3+
import { pipeline } from "../src/pipeline";
4+
import { fromIterable } from "../src/fromIterable";
5+
import { map } from "../src/map";
6+
import { filter } from "../src/filter";
7+
import { sum } from "../src/numbers/sum";
8+
import { forEach } from "../src/forEach";
9+
10+
describe("map-filter-reduce", () => {
11+
const initialArray = new Array(10_000).fill(0).map((_, index) => index);
12+
13+
bench("normal", () => {
14+
const result = initialArray
15+
.map((value) => value * 2)
16+
.filter((value) => value % 2 === 0)
17+
.reduce((accumulator, value) => accumulator + value, 0);
18+
});
19+
20+
bench("re-flusso", async () => {
21+
let result: number;
22+
23+
await pipeline(
24+
fromIterable(initialArray),
25+
map((value) => value * 2),
26+
filter((value) => value % 2 === 0),
27+
sum(),
28+
forEach<number>((sumResult) => {
29+
result = sumResult;
30+
}),
31+
);
32+
});
33+
});

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323
"url": "https://github.com/ilteoood/re-flusso"
2424
},
2525
"scripts": {
26-
"format": "biome format ./src ./test ./examples",
26+
"format": "biome format ./src ./test ./examples ./benchmarks",
2727
"format:fix": "pnpm run format --write",
28-
"sort": "biome check --apply-unsafe ./src ./test ./examples",
29-
"lint": "biome lint ./src ./test ./examples",
30-
"lint:fix": "biome check --write ./src ./test ./examples",
28+
"sort": "biome check --apply-unsafe ./src ./test ./examples ./benchmarks",
29+
"lint": "biome lint ./src ./test ./examples ./benchmarks",
30+
"lint:fix": "biome check --write ./src ./test ./examples ./benchmarks",
3131
"test": "pnpm run \"/^test:.*/\"",
3232
"test:node": "vitest --config ./vitest-node.config.ts",
3333
"test:browser": "vitest --config ./vitest-browser.config.ts",
3434
"test:edge": "vitest --config ./vitest-edge.config.ts",
3535
"build": "tsup",
36-
"prepublish": "pnpm run build"
36+
"prepublish": "pnpm run build",
37+
"benchmark": "vitest bench --config ./vitest-benchmark.config.ts"
3738
},
3839
"keywords": [
3940
"streams",

vitest-benchmark.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
pool: 'forks',
6+
benchmark: {
7+
include: ['benchmarks/**/*.test.ts'],
8+
}
9+
},
10+
})

vitest-browser.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'
22

33
export default defineConfig({
44
test: {
5-
environment: 'edge-runtime'
5+
environment: 'edge-runtime',
6+
include: ['test/**/*.test.ts']
67
},
78
})

vitest-edge.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'
22

33
export default defineConfig({
44
test: {
5-
environment: 'edge-runtime'
5+
environment: 'edge-runtime',
6+
include: ['test/**/*.test.ts']
67
},
78
})

vitest-node.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { defineConfig } from 'vitest/config'
33
export default defineConfig({
44
test: {
55
pool: 'forks',
6+
include: ['test/**/*.test.ts']
67
},
78
})

0 commit comments

Comments
 (0)