-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.ts
108 lines (86 loc) · 2.46 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
106
107
108
import * as denoRedis from "https://deno.land/x/[email protected]/mod.ts";
import { Redis } from "npm:[email protected]";
import { createClient } from "npm:[email protected]";
import { RedisClient } from "./mod.ts";
const HOSTNAME = "127.0.0.1";
const PORT = 6379;
const redisConn = await Deno.connect({ hostname: HOSTNAME, port: PORT });
const redisClient = new RedisClient(redisConn);
const denoRedisConn = await denoRedis.connect({
hostname: HOSTNAME,
port: PORT,
});
const ioRedis = new Redis();
const nodeRedisClient = await createClient().connect();
Deno.bench({
name: "r2d2",
baseline: true,
async fn() {
await redisClient.sendCommand(["PING"]);
await redisClient.sendCommand(["SET", "mykey", "Hello"]);
await redisClient.sendCommand(["GET", "mykey"]);
await redisClient.sendCommand(["HSET", "hash", "a", "foo", "b", "bar"]);
await redisClient.sendCommand(["HGETALL", "hash"]);
await redisClient.pipelineCommands([
["INCR", "X"],
["INCR", "X"],
["INCR", "X"],
["INCR", "X"],
]);
},
});
Deno.bench({
name: "deno-redis",
async fn() {
await denoRedisConn.ping();
await denoRedisConn.set("mykey", "Hello");
await denoRedisConn.get("mykey");
await denoRedisConn.hset("hash", { a: "foo", b: "bar" });
await denoRedisConn.hgetall("hash");
const pl = denoRedisConn.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");
/** Auto-pipelining */
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", () => {
denoRedisConn.close();
redisConn.close();
});