Skip to content

Commit

Permalink
Merge pull request #18 from scmmishra/feat/perf-testing
Browse files Browse the repository at this point in the history
feat: perf testing
  • Loading branch information
scmmishra authored May 27, 2024
2 parents 92bae0e + 8850be3 commit 1411b76
Show file tree
Hide file tree
Showing 8 changed files with 2,474 additions and 1,620 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9
run_install: |
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9
run_install: |
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
Expand Down
68 changes: 68 additions & 0 deletions bench/pico.perf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { bench, describe } from "vitest";
import { picoSearch } from "../src/pico";
import { weightedAverage, clamp, splitAndTrim } from "../src/utils";
import jaroWinkler from "../src/algorithms/jaroWinkler";

// generate 10000 random strings of 10 characters
const testData = Array.from({ length: 50000 }, (ii) => {
return {
name: `${Math.random() * 1000} data-point-${ii} fixed-target`,
};
});

describe("picoSearch", () => {
bench("Search 50K items", () => {
picoSearch(testData, "data-point-39900", ["name"], { threshold: 0.8 });
});

bench("Search 5000 items", () => {
picoSearch(testData.slice(0, 5000), "data-point-39900", ["name"], {
threshold: 0.8,
});
});

bench("Search 500 items", () => {
picoSearch(testData.slice(0, 500), "data-point-39900", ["name"], {
threshold: 0.8,
});
});
});

describe("utils: weightedAverage", () => {
bench("specific weights", () => {
weightedAverage([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]);
});

bench("uniform weights", () => {
weightedAverage([1, 2, 3, 4, 5], [1, 1, 1, 1, 1]);
});
});

describe("utils: clamp", () => {
bench("base", () => {
clamp(10);
});
});

describe("utils: splitAndTrim", () => {
bench("basic string", () => {
splitAndTrim("Hello world");
});
bench("no spaces", () => {
splitAndTrim("Helloworld");
});
bench("long string", () => {
splitAndTrim("Hello world this is a good day");
});
bench("duplicates", () => {
splitAndTrim("Hello hello this this this this");
});
});

describe("jaroWinkler", () => {
bench("Find distance", () => {
testData.forEach(({ name }) => {
jaroWinkler(name, "data-point-12345");
});
});
});
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@
"dev": "tsup --watch",
"build": "tsup",
"test": "vitest",
"benchmark": "vitest bench",
"size": "size-limit",
"coverage": "vitest run --coverage"

},
"devDependencies": {
"@size-limit/esbuild": "^8.2.6",
"@size-limit/esbuild-why": "^8.2.6",
"@size-limit/preset-small-lib": "^8.2.6",
"@types/node": "^18.16.0",
"@vitest/coverage-c8": "^0.29.8",
"jsdom": "^21.1.1",
"size-limit": "^8.2.6",
"tsup": "^6.7.0",
"typescript": "^4.9.5",
"vite": "^4.3.9",
"vitest": "^0.29.8"
"@size-limit/esbuild": "^11.1.4",
"@size-limit/esbuild-why": "^11.1.4",
"@size-limit/preset-small-lib": "^11.1.4",
"@types/node": "^20.12.12",
"jsdom": "^24.1.0",
"size-limit": "^11.1.4",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0",
"@vitest/coverage-v8": "^1.6.0"
},
"size-limit": [
{
Expand Down
Loading

0 comments on commit 1411b76

Please sign in to comment.