-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.ts
105 lines (83 loc) · 2.44 KB
/
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { connect } from "https://deno.land/x/redis@v0.29.2/mod.ts";
import { Redis } from "https://esm.sh/ioredis@5.3.1";
import nodeRedis from "https://esm.sh/redis@4.6.5";
import { pipelineCommands, sendCommand } from "./mod.ts";
const HOSTNAME = "127.0.0.1";
const PORT = 6379;
const redisConn = await Deno.connect({ hostname: HOSTNAME, port: PORT });
const denoRedis = await connect({ hostname: HOSTNAME, port: PORT });
const ioRedis = new Redis();
const nodeRedisClient = nodeRedis.createClient({ socket: { host: HOSTNAME } });
await nodeRedisClient.connect();
Deno.bench({
name: "r2d2",
baseline: true,
async fn() {
await sendCommand(redisConn, ["PING"]);
await sendCommand(redisConn, ["SET", "mykey", "Hello"]);
await sendCommand(redisConn, ["GET", "mykey"]);
await sendCommand(redisConn, ["HSET", "hash", "a", "foo", "b", "bar"]);
await sendCommand(redisConn, ["HGETALL", "hash"]);
await pipelineCommands(redisConn, [
["INCR", "X"],
["INCR", "X"],
["INCR", "X"],
["INCR", "X"],
]);
},
});
Deno.bench({
name: "deno-redis",
async fn() {
await denoRedis.ping();
await denoRedis.set("mykey", "Hello");
await denoRedis.get("mykey");
await denoRedis.hset("hash", { a: "foo", b: "bar" });
await denoRedis.hgetall("hash");
const pl = denoRedis.pipeline();
pl.incr("X");
pl.incr("X");
pl.incr("X");
pl.incr("X");
await pl.flush();
},
});
Deno.bench({
name: "npm:ioredis",
async fn() {
await ioRedis.ping();
await ioRedis.set("mykey", "Hello");
await ioRedis.get("mykey");
await ioRedis.hset("hash", { a: "foo", b: "bar" });
await ioRedis.hgetall("hash");
const pl = ioRedis.pipeline();
pl.incr("X");
pl.incr("X");
pl.incr("X");
pl.incr("X");
await pl.exec();
},
});
Deno.bench({
name: "npm:redis",
async fn() {
await nodeRedisClient.ping();
await nodeRedisClient.set("mykey", "Hello");
await nodeRedisClient.get("mykey");
await nodeRedisClient.hSet("hash", { a: "foo", b: "bar" });
await nodeRedisClient.hGetAll("hash");
/** Autopipelining */
await nodeRedisClient.incr("X");
await nodeRedisClient.incr("X");
await nodeRedisClient.incr("X");
await nodeRedisClient.incr("X");
},
});
addEventListener("beforeunload", async () => {
ioRedis.disconnect();
await nodeRedisClient.disconnect();
});
addEventListener("unload", () => {
denoRedis.close();
redisConn.close();
});