Skip to content

Commit

Permalink
chore(*): Add codspeed for benchmark visualization (#75)
Browse files Browse the repository at this point in the history
* chore: add codspeed

* chore: fix the benchmark file to clearly distinguish between the comparison targets

* chore: fix typo
  • Loading branch information
juno7803 authored Jun 18, 2024
1 parent e3dbe50 commit 3cc1a03
Show file tree
Hide file tree
Showing 44 changed files with 236 additions and 88 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: codspeed-benchmarks

on:
push:
branches:
- 'main'
pull_request:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'yarn'
name: Install dependencies
- run: yarn install
- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
run: yarn vitest bench
token: ${{ secrets.CODSPEED_TOKEN }}
4 changes: 2 additions & 2 deletions benchmarks/chunk.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { chunk as chunkToolkit } from 'es-toolkit';
import { chunk as chunkLodash } from 'lodash';

describe('chunk', () => {
bench('es-toolkit', () => {
bench('es-toolkit/chunk', () => {
chunkToolkit([1, 2, 3, 4, 5, 6], 3);
});

bench('lodash', () => {
bench('lodash/chunk', () => {
chunkLodash([1, 2, 3, 4, 5, 6], 3);
});
});
4 changes: 2 additions & 2 deletions benchmarks/clamp.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { clamp as clampToolkit } from 'es-toolkit';
import { clamp as clampLodash } from 'lodash';

describe('clamp', () => {
bench('es-toolkit', () => {
bench('es-toolkit/clamp', () => {
clampToolkit(10, 5, 15);
clampToolkit(10, 5);
});

bench('lodash', () => {
bench('lodash/clamp', () => {
clampLodash(10, 5, 15);
clampLodash(10, 5);
});
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/difference.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { difference as differenceToolkit } from 'es-toolkit';
import { difference as differenceLodash } from 'lodash';

describe('difference', () => {
bench('es-toolkit', () => {
bench('es-toolkit/difference', () => {
differenceToolkit([1, 2, 3], [2]);
});

bench('lodash', () => {
bench('lodash/difference', () => {
differenceLodash([1, 2, 3], [2]);
});
});
4 changes: 2 additions & 2 deletions benchmarks/differenceBy.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { differenceBy as differenceByToolkit } from 'es-toolkit';
import { differenceBy as differenceByLodash } from 'lodash';

describe('differenceBy', () => {
bench('es-toolkit', () => {
bench('es-toolkit/differenceBy', () => {
differenceByToolkit([1.2, 2.3, 3.4], [1.2], Math.floor);
});

bench('lodash', () => {
bench('lodash/differenceBy', () => {
differenceByLodash([1.2, 2.3, 3.4], [1.2], Math.floor);
});
});
4 changes: 2 additions & 2 deletions benchmarks/differenceWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { differenceWith as differenceWithToolkit } from 'es-toolkit';
import { differenceWith as differenceWithLodash } from 'lodash';

describe('differenceWith', () => {
bench('es-toolkit', () => {
bench('es-toolkit/differenceWith', () => {
differenceWithToolkit([1.2, 2.3, 3.4], [1.2], (x, y) => Math.floor(x) === Math.floor(y));
});

bench('lodash', () => {
bench('lodash/differenceWith', () => {
differenceWithLodash([1.2, 2.3, 3.4], [1.2], (x, y) => Math.floor(x) === Math.floor(y));
});
});
4 changes: 2 additions & 2 deletions benchmarks/drop.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { drop as dropToolkit } from 'es-toolkit';
import { drop as dropLodash } from 'lodash';

describe('drop', () => {
bench('es-toolkit', () => {
bench('es-toolkit/drop', () => {
dropToolkit([1, 2, 3, 4, 5, 6], 3);
});

bench('lodash', () => {
bench('lodash/drop', () => {
dropLodash([1, 2, 3, 4, 5, 6], 3);
});
});
4 changes: 2 additions & 2 deletions benchmarks/dropRight.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { dropRight as dropRightToolkit } from 'es-toolkit';
import { dropRight as dropRightLodash } from 'lodash';

describe('dropRight', () => {
bench('es-toolkit', () => {
bench('es-toolkit/dropRight', () => {
dropRightToolkit([1, 2, 3, 4, 5, 6], 3);
});

bench('lodash', () => {
bench('lodash/dropRight', () => {
dropRightLodash([1, 2, 3, 4, 5, 6], 3);
});
});
4 changes: 2 additions & 2 deletions benchmarks/dropRightWhile.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { dropRightWhile as dropRightWhileToolkit } from 'es-toolkit';
import { dropRightWhile as dropRightWhileLodash } from 'lodash';

describe('dropRightWhile', () => {
bench('es-toolkit', () => {
bench('es-toolkit/dropRightWhile', () => {
dropRightWhileToolkit([1.2, 2.3, 3.4], x => x < 2);
});

bench('lodash', () => {
bench('lodash/dropRightWhile', () => {
dropRightWhileLodash([1.2, 2.3, 3.4], x => x < 2);
});
});
4 changes: 2 additions & 2 deletions benchmarks/dropWhile.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { dropWhile as dropWhileToolkit } from 'es-toolkit';
import { dropWhile as dropWhileLodash } from 'lodash';

describe('dropWhile', () => {
bench('es-toolkit', () => {
bench('es-toolkit/dropWhile', () => {
dropWhileToolkit([1.2, 2.3, 3.4], x => x < 2);
});

bench('lodash', () => {
bench('lodash/dropWhile', () => {
dropWhileLodash([1.2, 2.3, 3.4], x => x < 2);
});
});
4 changes: 2 additions & 2 deletions benchmarks/groupBy.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { groupBy as groupByToolkit } from 'es-toolkit';
import { groupBy as groupByLodash } from 'lodash';

describe('groupBy', () => {
bench('es-toolkit', () => {
bench('es-toolkit/groupBy', () => {
const array = [
{ category: 'fruit', name: 'apple' },
{ category: 'fruit', name: 'banana' },
Expand All @@ -15,7 +15,7 @@ describe('groupBy', () => {
groupByToolkit(array, item => item.category);
});

bench('lodash', () => {
bench('lodash/groupBy', () => {
const array = [
{ category: 'fruit', name: 'apple' },
{ category: 'fruit', name: 'banana' },
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/intersection.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ describe('intersection, small arrays', () => {
const array1 = [1, 2, 3];
const array2 = [2, 4];

bench('es-toolkit', () => {
bench('es-toolkit/intersection', () => {
intersectionToolkit(array1, array2);
});

bench('lodash', () => {
bench('lodash/intersection', () => {
intersectionLodash(array1, array2);
});
});
Expand All @@ -19,11 +19,11 @@ describe('intersection, large arrays', () => {
const array1 = Array.from({ length: 10000 }, () => Math.floor(Math.random() * 1000));
const array2 = Array.from({ length: 10000 }, () => Math.floor(Math.random() * 1000));

bench('es-toolkit', () => {
bench('es-toolkit/intersection', () => {
intersectionToolkit(array1, array2);
});

bench('lodash', () => {
bench('lodash/intersection', () => {
intersectionLodash(array1, array2);
});
});
4 changes: 2 additions & 2 deletions benchmarks/intersectionBy.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { intersectionBy as intersectionByToolkit } from 'es-toolkit';
import { intersectionBy as intersectionByLodash } from 'lodash';

describe('intersectionBy', () => {
bench('es-toolkit', () => {
bench('es-toolkit/intersectionBy', () => {
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
const array2 = [{ id: 2 }, { id: 4 }];
const mapper = item => item.id;
intersectionByToolkit(array1, array2, mapper);
});

bench('lodash', () => {
bench('lodash/intersectionBy', () => {
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
const array2 = [{ id: 2 }, { id: 4 }];
const mapper = item => item.id;
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/intersectionWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { intersectionWith as intersectionWithToolkit } from 'es-toolkit';
import { intersectionWith as intersectionWithLodash } from 'lodash';

describe('intersectionWith', () => {
bench('es-toolkit', () => {
bench('es-toolkit/intersectionWith', () => {
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
const array2 = [{ id: 2 }, { id: 4 }];
const areItemsEqual = (a, b) => a.id === b.id;
intersectionWithToolkit(array1, array2, areItemsEqual);
});

bench('lodash', () => {
bench('lodash/intersectionWith', () => {
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
const array2 = [{ id: 2 }, { id: 4 }];
const areItemsEqual = (a, b) => a.id === b.id;
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/isNil.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { isNil as isNilToolkit } from 'es-toolkit';
import { isNil as isNilLodash } from 'lodash';

describe('isNil', () => {
bench('es-toolkit', () => {
bench('es-toolkit/isNil', () => {
isNilToolkit(null);
isNilToolkit(undefined);
isNilToolkit(123);
isNilToolkit([1, 2, 3]);
});

bench('lodash', () => {
bench('lodash/isNil', () => {
isNilLodash(null);
isNilLodash(undefined);
isNilLodash(123);
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/maxBy.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { maxBy as maxByToolkit } from 'es-toolkit';
import { maxBy as maxByLodash } from 'lodash';

describe('maxBy', () => {
bench('es-toolkit', () => {
bench('es-toolkit/maxBy', () => {
const people = [
{ name: 'Mark', age: 25 },
{ name: 'Nunu', age: 30 },
Expand All @@ -12,7 +12,7 @@ describe('maxBy', () => {
maxByToolkit(people, person => person.age);
});

bench('lodash', () => {
bench('lodash/maxBy', () => {
const people = [
{ name: 'Mark', age: 25 },
{ name: 'Nunu', age: 30 },
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/minBy.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { minBy as minByToolkit } from 'es-toolkit';
import { minBy as minByLodash } from 'lodash';

describe('minBy', () => {
bench('es-toolkit', () => {
bench('es-toolkit/minBy', () => {
const people = [
{ name: 'Mark', age: 30 },
{ name: 'Nunu', age: 20 },
Expand All @@ -12,7 +12,7 @@ describe('minBy', () => {
minByToolkit(people, person => person.age);
});

bench('lodash', () => {
bench('lodash/minBy', () => {
const people = [
{ name: 'Mark', age: 30 },
{ name: 'Nunu', age: 20 },
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/omit.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { omit as omitToolkit } from 'es-toolkit';
import { omit as omitLodash } from 'lodash';

describe('omit', () => {
bench('es-toolkit', () => {
bench('es-toolkit/omit', () => {
omitToolkit({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
});

bench('lodash', () => {
bench('lodash/omit', () => {
omitLodash({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
});
});
4 changes: 2 additions & 2 deletions benchmarks/omitBy.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { omitBy as omitByLodash } from 'lodash';
import { bench, describe } from 'vitest';

describe('omitBy', () => {
bench('es-toolkit', () => {
bench('es-toolkit/omitBy', () => {
const obj = { a: 1, b: 'omit', c: 3 };
const shouldOmit = (value: number | string) => typeof value === 'string';
omitByToolkit(obj, shouldOmit);
});

bench('lodash', () => {
bench('lodash/omitBy', () => {
const obj = { a: 1, b: 'omit', c: 3 };
const shouldOmit = (value: number | string) => typeof value === 'string';
omitByLodash(obj, shouldOmit);
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/partition.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { partition as partitionToolkit } from 'es-toolkit';
import { partition as partitionLodash } from 'lodash';

describe('partition', () => {
bench('es-toolkit', () => {
bench('es-toolkit/partition', () => {
partitionToolkit([1, 2, 3, 4, 5], x => x < 3);
});

bench('lodash', () => {
bench('lodash/partition', () => {
partitionLodash([1, 2, 3], x => x < 3);
});
});
4 changes: 2 additions & 2 deletions benchmarks/pick.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { pick as pickToolkit } from 'es-toolkit';
import { pick as pickLodash } from 'lodash';

describe('pick', () => {
bench('es-toolkit', () => {
bench('es-toolkit/pick', () => {
pickToolkit({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
});

bench('lodash', () => {
bench('lodash/pick', () => {
pickLodash({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar']);
});
});
4 changes: 2 additions & 2 deletions benchmarks/random.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { random as randomToolkit } from 'es-toolkit';
import { random as randomLodash } from 'lodash';

describe('random', () => {
bench('es-toolkit', () => {
bench('es-toolkit/random', () => {
randomToolkit(1, 10);
});

bench('lodash', () => {
bench('lodash/random', () => {
randomLodash(1, 10, true);
});
});
4 changes: 2 additions & 2 deletions benchmarks/round.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { round as roundToolkit } from 'es-toolkit';
import { round as roundLodash } from 'lodash';

describe('round', () => {
bench('es-toolkit', () => {
bench('es-toolkit/round', () => {
roundToolkit(1.2345, 2);
});

bench('lodash', () => {
bench('lodash/round', () => {
roundLodash(1.2345, 2);
});
});
4 changes: 2 additions & 2 deletions benchmarks/sample.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { sample as sampleToolkit } from 'es-toolkit';
import { sample as sampleLodash } from 'lodash';

describe('sample', () => {
bench('es-toolkit', () => {
bench('es-toolkit/sample', () => {
const array = [1, 2, 3, 4, 5];
sampleToolkit(array);
});

bench('lodash', () => {
bench('lodash/sample', () => {
const array = [1, 2, 3, 4, 5];
sampleLodash(array);
});
Expand Down
Loading

0 comments on commit 3cc1a03

Please sign in to comment.