Skip to content

Commit

Permalink
Merge pull request #16 from ilteoood/feat/benchmarks
Browse files Browse the repository at this point in the history
Feat/benchmarks
  • Loading branch information
ilteoood authored Jun 21, 2024
2 parents eee3cff + faa6294 commit 336206f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 7 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/bechmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Benchmark workflow
on: [push, pull_request]
jobs:
benchmark:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: pnpm/action-setup@v2
with:
version: latest
- run: pnpm install --frozen-lockfile
- run: pnpm run benchmark
33 changes: 33 additions & 0 deletions benchmarks/map-filter-reduce.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, bench } from "vitest";

import { pipeline } from "../src/pipeline";
import { fromIterable } from "../src/fromIterable";
import { map } from "../src/map";
import { filter } from "../src/filter";
import { sum } from "../src/numbers/sum";
import { forEach } from "../src/forEach";

describe("map-filter-reduce", () => {
const initialArray = new Array(10_000).fill(0).map((_, index) => index);

bench("normal", () => {
const result = initialArray
.map((value) => value * 2)
.filter((value) => value % 2 === 0)
.reduce((accumulator, value) => accumulator + value, 0);
});

bench("re-flusso", async () => {
let result: number;

await pipeline(
fromIterable(initialArray),
map((value) => value * 2),
filter((value) => value % 2 === 0),
sum(),
forEach<number>((sumResult) => {
result = sumResult;
}),
);
});
});
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
"url": "https://github.com/ilteoood/re-flusso"
},
"scripts": {
"format": "biome format ./src ./test ./examples",
"format": "biome format ./src ./test ./examples ./benchmarks",
"format:fix": "pnpm run format --write",
"sort": "biome check --apply-unsafe ./src ./test ./examples",
"lint": "biome lint ./src ./test ./examples",
"lint:fix": "biome check --write ./src ./test ./examples",
"sort": "biome check --apply-unsafe ./src ./test ./examples ./benchmarks",
"lint": "biome lint ./src ./test ./examples ./benchmarks",
"lint:fix": "biome check --write ./src ./test ./examples ./benchmarks",
"test": "pnpm run \"/^test:.*/\"",
"test:node": "vitest --config ./vitest-node.config.ts",
"test:browser": "vitest --config ./vitest-browser.config.ts",
"test:edge": "vitest --config ./vitest-edge.config.ts",
"build": "tsup",
"prepublish": "pnpm run build"
"prepublish": "pnpm run build",
"benchmark": "vitest bench --config ./vitest-benchmark.config.ts"
},
"keywords": [
"streams",
Expand Down
10 changes: 10 additions & 0 deletions vitest-benchmark.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
pool: 'forks',
benchmark: {
include: ['benchmarks/**/*.test.ts'],
}
},
})
3 changes: 2 additions & 1 deletion vitest-browser.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
environment: 'edge-runtime'
environment: 'edge-runtime',
include: ['test/**/*.test.ts']
},
})
3 changes: 2 additions & 1 deletion vitest-edge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
environment: 'edge-runtime'
environment: 'edge-runtime',
include: ['test/**/*.test.ts']
},
})
1 change: 1 addition & 0 deletions vitest-node.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
pool: 'forks',
include: ['test/**/*.test.ts']
},
})

0 comments on commit 336206f

Please sign in to comment.