-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_redis.mjs
65 lines (50 loc) · 2.01 KB
/
benchmark_redis.mjs
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 { createClient } from 'redis';
const client = await createClient()
.on('error', err => console.log('Redis Client Error', err))
.connect();
let max = 100000;
console.log('Redis performance test');
console.log('Insert and read back ' + max.toLocaleString() + ' key/value pairs using HSET and HGET');
console.log('Please wait...')
console.log('-----');
let start = Date.now();
for (let key = 1; key < max; key++) {
await client.HSET('redistest', key, 'hello world');
}
let finish = Date.now();
let elap = (finish - start)/1000;
console.log('finished ' + max.toLocaleString() + ' inserts in ' + Math.trunc(elap) + ' seconds');
console.log('rate: ' + Math.trunc((max / elap)).toLocaleString() + ' /sec');
console.log('------');
start = Date.now();
for (let key = 1; key < max; key++) {
let value = await client.HGET('redistest', key.toString());
}
finish = Date.now();
elap = (finish - start)/1000;
console.log('finished ' + max.toLocaleString() + ' gets in ' + Math.trunc(elap) + ' seconds');
console.log('rate: ' + Math.trunc((max / elap)).toLocaleString() + ' /sec');
console.log('-----------');
console.log(' ');
console.log('Redis performance test');
console.log('Insert and read back ' + max.toLocaleString() + ' key/value pairs using SET and GET');
console.log('Please wait...')
console.log('-----');
start = Date.now();
for (let key = 1; key < max; key++) {
await client.SET('redistest:' + key, 'hello world');
}
finish = Date.now();
elap = (finish - start)/1000;
console.log('finished ' + max.toLocaleString() + ' inserts in ' + Math.trunc(elap) + ' seconds');
console.log('rate: ' + Math.trunc((max / elap)).toLocaleString() + ' /sec');
console.log('------');
start = Date.now();
for (let key = 1; key < max; key++) {
let value = await client.GET('redistest:' + key);
}
finish = Date.now();
elap = (finish - start)/1000;
console.log('finished ' + max.toLocaleString() + ' gets in ' + Math.trunc(elap) + ' seconds');
console.log('rate: ' + Math.trunc((max / elap)).toLocaleString() + ' /sec');
await client.disconnect();