-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.js
56 lines (44 loc) · 1.03 KB
/
bench.js
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
'use strict'
const Redis = require('ioredis')
const auto = require('.')
let redis = new Redis({
port: 6379,
host: '127.0.0.1'
})
if (process.argv[2] !== 'single') {
redis = auto(redis)
}
const key = 'TEST-KEY'
;(async function start () {
await redis.set(
key,
JSON.stringify({
hello: 'world'
})
)
let prevElapsed = 0
let firsElapsed = 0
const results = []
let start = Date.now()
let last = null
const iterations = 1000
start = Date.now()
await Promise.all(Array(iterations).fill(1).map(async (_, i) => {
const ret = await redis.get(key)
JSON.parse(ret)
const now = Date.now()
const elapsed = now - start
results.push({
index: i,
elapsed,
diff: elapsed - prevElapsed,
'total-diff': elapsed - firsElapsed
})
prevElapsed = elapsed
if (!firsElapsed) firsElapsed = elapsed
if (now > last) last = now
}))
console.table(results, ['index', 'elapsed', 'diff', 'total-diff'])
console.log('\ntotal-diff', last - start)
redis.quit()
})()