Skip to content

Commit

Permalink
ci(benchmark): Migrate to benny (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Apr 24, 2022
1 parent 330e0a7 commit dff665c
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 102 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ jobs:
with:
working-directory: benchmark
- name: Run benchmarks
working-directory: benchmark
run: |
deno bundle benchmark.ts > benchmark.js
deno run -A deno-redis.ts
node ioredis.js
deno task bench:ioredis
deno task bench:deno-redis
- uses: actions/upload-artifact@v3
with:
name: benchmark
path: tmp/*.html
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ deno.d.ts
.idea
testdata/*/
benchmark/node_modules
benchmark/benchmark.js
tests/tmp/*/
tests/tmp/*/
tmp
67 changes: 67 additions & 0 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { add, complete, configure, cycle, save, suite } from "benny";
import { dirname, join } from "node:path";

export function run({
driver,
client,
}) {
return suite(
driver,
configure({ minSamples: 10 }),
add("ping", async () => {
await client.ping("HELLO");
}),
add("set & get", () => {
const value = "bar".repeat(10);
return async () => {
const key = "foo";
await client.set(key, value);
await client.get(key);
};
}),
add("mset & mget", async () => {
await client.mset({ a: "foo", b: "bar" });
await client.mget("a", "b");
}),
add("zadd & zscore", async () => {
await client.zadd("zset", 1234567, "member");
await client.zscore("zset", "member");
}),
cycle(),
complete((summary) => {
const results = summary.results.map((result) => {
const {
name,
ops,
margin,
details: {
min,
max,
mean,
median,
},
samples,
} = result;
return {
name,
ops,
margin,
min,
max,
mean,
median,
samples,
};
});
console.table(results);
}),
complete(async () => {
await client.flushdb();
}),
save({
file: `${driver}-bench`,
format: "chart.html",
folder: join(dirname(dirname(new URL(import.meta.url).pathname)), "tmp"),
}),
);
}
88 changes: 0 additions & 88 deletions benchmark/benchmark.ts

This file was deleted.

2 changes: 1 addition & 1 deletion benchmark/deno-redis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { run } from "./benchmark.ts";
import { run } from "./benchmark.js";
import { connect } from "../mod.ts";

const redis = await connect({ hostname: "127.0.0.1" });
Expand Down
5 changes: 0 additions & 5 deletions benchmark/ioredis.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// deno-lint-ignore-file
import { run } from "./benchmark.js";
import { performance } from "perf_hooks";
import Redis from "ioredis";

global.performance = performance;
global.Deno = {};

const redis = new Redis();
redis.on("connect", async () => {
await run({
Expand Down
1 change: 1 addition & 0 deletions benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"license": "MIT",
"private": true,
"devDependencies": {
"benny": "^3.7.1",
"ioredis": "^4.22.0"
}
}
Loading

0 comments on commit dff665c

Please sign in to comment.