-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.bench.ts
65 lines (51 loc) · 1.46 KB
/
plugin.bench.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import fastify from "fastify";
import ironSession from "./plugin";
import { bench, describe } from "vitest";
describe("benchmarks", () => {
const benchAppWithPlugin = fastify();
const benchAppWithoutPlugin = fastify();
benchAppWithPlugin.register(ironSession, {
cookieName: "test",
password: "at-least-32-characters-long-secret",
});
benchAppWithPlugin.get("/", async (request, reply) => {
return { hello: "world" };
});
benchAppWithoutPlugin.get("/", async (request, reply) => {
return { hello: "world" };
});
benchAppWithPlugin.get("/save", async (request, reply) => {
const session = await request.session();
session.id = "123";
await session.save();
return { hello: "world" };
});
benchAppWithPlugin.get("/read", async (request, reply) => {
const session = await request.session();
return { hello: "world", id: session.id };
});
bench("request with plugin", async () => {
await benchAppWithPlugin.inject({
method: "GET",
url: "/",
});
});
bench("request without plugin", async () => {
await benchAppWithoutPlugin.inject({
method: "GET",
url: "/",
});
});
bench("request with plugin and save session", async () => {
await benchAppWithPlugin.inject({
method: "GET",
url: "/save",
});
});
bench("request with plugin and read session", async () => {
await benchAppWithPlugin.inject({
method: "GET",
url: "/read",
});
});
});