Skip to content

Commit

Permalink
chore(benchmark): EXPERIMENTAL - creates benchmark file on push
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Jul 19, 2022
1 parent 0e368ab commit c68bdb3
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Benchmarks
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install pnpm
uses: pnpm/action-setup@v2.0.1
id: pnpm-install
with:
version: 7
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Install benchmark dependencies
run: cd ./packages/benchmarks && pnpm install

- name: Build Lyra
run: cd ./packages/lyra && pnpm build

- name: Create benchmark file
run: |
node ./packages/benchmarks/benchmark-table/index.mjs >> ./packages/benchmarks/README.md
- name: stage changed files
run: git add .

- name: commit changed files
run: |
git commit -m "chore(benchmarks): update benchmark table"
- name: fetch from master
run: git fetch origin master

- name: push code to master
run: git push origin HEAD:master
Empty file added packages/benchmarks/README.md
Empty file.
73 changes: 73 additions & 0 deletions packages/benchmarks/benchmark-table/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* global console */
import { Lyra } from "@nearform/lyra";
import lines from "../dataset/divinaCommedia.json" assert { type: "json" };

const db = new Lyra({
schema: {
id: "string",
txt: "string",
},
});

for (const line of lines) {
await db.insert(line);
}

const d1 = await db.search({
term: "stelle",
properties: ["txt"],
exact: true,
});

const d2 = await db.search({
term: "stelle",
exact: true,
});

const d3 = await db.search({
term: "stele",
properties: "*",
tolerance: 1,
});

const d4 = await db.search({
term: "onde si muovono a diversi porti",
properties: "*",
exact: true,
});

const d5 = await db.search({
term: "ode si mossero a divisi porte",
properties: "*",
tolerance: 5
});

const d6 = await db.search({
term: "ode si mossero a divisi porte",
properties: ["txt"],
tolerance: 5
});

const table = `
| Search | Term | Properties | Typo tolerance | Time Elapsed | Results |
|--------------------|---------------------------------------|------------|----------------|---------------|-------------|
| **Exact search** | \`"stelle"\` | \`["txt"]\`| \`N/A\` | ${d1.elapsed} | ${d1.count} |
| **Exact search** | \`"stelle"\` | \`"*"\` | \`N/A\` | ${d2.elapsed} | ${d2.count} |
| **Typo tolerance** | \`"stele"\` | \`"*"\` | \`1\` | ${d3.elapsed} | ${d3.count} |
| **Exact search** | \`"onde si muovono a diversi porti"\` | \`"*"\` | \`N/A\` | ${d4.elapsed} | ${d4.count} |
| **Typo tolerance** | \`"ode si mossero a divisi porte"\` | \`"*"\` | \`5\` | ${d5.elapsed} | ${d5.count} |
| **Typo tolerance** | \`"ode si mossero a divisi porte"\` | \`["txt"]\`| \`5\` | ${d6.elapsed} | ${d6.count} |
`;

const markdownContent = `
# Benchmakrs
The following is an automated benchmark performed on the [Divina Commedia](https://en.wikipedia.org/wiki/Divina_Commedia) dataset. <br />
You can find the full dataset [here](https://github.com/nearform/lyra/blob/main/packages/benchmarks/dataset/divinaCommedia.json).
# Results
${table}
`;

console.log(markdownContent);

0 comments on commit c68bdb3

Please sign in to comment.