Skip to content

Instantly share code, notes, and snippets.

@reconbot
Last active March 18, 2017 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reconbot/13bd36d2d868c6f92ac7dc7104119081 to your computer and use it in GitHub Desktop.
Save reconbot/13bd36d2d868c6f92ac7dc7104119081 to your computer and use it in GitHub Desktop.
Ran this on my macbook pro with a local redis https://github.com/thunks/thunk-redis/blob/master/benchmark/index.js
★ thunk-redis git:(master) ✗ node benchmark
redis(redis): node_redis OK
redis(thunk-redis):thunk-redis OK
redis(ioredis): ioRedis OK
Bench start:(100000)
PING concurrency(full thread):
redis(redis): 1058ms 94517ops/sec 100%
redis(thunk-redis): 1117ms 89525ops/sec 94.7%
redis(ioredis): 1820ms 54945ops/sec 58.1%
PING concurrency(1000 thread):
redis(redis): 944ms 105932ops/sec 100%
redis(thunk-redis): 1155ms 86580ops/sec 81.7%
redis(ioredis): 1490ms 67114ops/sec 63.4%
PING sequential 1 by 1:
redis(redis): 3919ms 25516ops/sec 100%
redis(thunk-redis): 5691ms 17571ops/sec 68.9%
redis(ioredis): 5024ms 19904ops/sec 78.0%
SET small string:
redis(redis): 1190ms 84033ops/sec 100%
redis(thunk-redis): 1283ms 77942ops/sec 92.8%
redis(ioredis): 1758ms 56882ops/sec 67.7%
GET small string:
redis(redis): 1189ms 84104ops/sec 100%
redis(thunk-redis): 1077ms 92850ops/sec 110.4%
redis(ioredis): 1756ms 56947ops/sec 67.7%
SET long string:
redis(redis): 1945ms 51413ops/sec 100%
redis(thunk-redis): 2771ms 36088ops/sec 70.2%
redis(ioredis): 2380ms 42016ops/sec 81.7%
GET long string:
redis(redis): 1648ms 60679ops/sec 100%
redis(thunk-redis): 2632ms 37993ops/sec 62.6%
redis(ioredis): 2775ms 36036ops/sec 59.4%
INCR:
redis(redis): 1040ms 96153ops/sec 100%
redis(thunk-redis): 1149ms 87032ops/sec 90.5%
redis(ioredis): 1872ms 53418ops/sec 55.6%
LPUSH:
redis(redis): 1158ms 86355ops/sec 100%
redis(thunk-redis): 1084ms 92250ops/sec 106.8%
redis(ioredis): 1570ms 63694ops/sec 73.8%
LRANGE 100:
redis(redis): 4728ms 21150ops/sec 100%
redis(thunk-redis): 8992ms 11120ops/sec 52.6%
redis(ioredis): 10123ms 9878ops/sec 46.7%
★ thunk-redis git:(master) ✗ node benchmark
redis(redis): node_redis OK
redis(thunk-redis):thunk-redis OK
redis(ioredis): ioRedis OK
Bench start:(100000)
PING concurrency(full thread):
redis(redis): 1172ms 85324ops/sec 100%
redis(thunk-redis): 1132ms 88339ops/sec 103.5%
redis(ioredis): 1833ms 54555ops/sec 63.9%
PING concurrency(1000 thread):
redis(redis): 971ms 102986ops/sec 100%
redis(thunk-redis): 1080ms 92592ops/sec 89.9%
redis(ioredis): 1472ms 67934ops/sec 66.0%
PING sequential 1 by 1:
redis(redis): 3867ms 25859ops/sec 100%
redis(thunk-redis): 5604ms 17844ops/sec 69.0%
redis(ioredis): 4785ms 20898ops/sec 80.8%
SET small string:
redis(redis): 1149ms 87032ops/sec 100%
redis(thunk-redis): 1239ms 80710ops/sec 92.7%
redis(ioredis): 1729ms 57836ops/sec 66.5%
GET small string:
redis(redis): 1161ms 86132ops/sec 100%
redis(thunk-redis): 1187ms 84245ops/sec 97.8%
redis(ioredis): 1593ms 62774ops/sec 72.9%
SET long string:
redis(redis): 1822ms 54884ops/sec 100%
redis(thunk-redis): 2798ms 35739ops/sec 65.1%
redis(ioredis): 2469ms 40502ops/sec 73.8%
GET long string:
redis(redis): 1817ms 55035ops/sec 100%
redis(thunk-redis): 3199ms 31259ops/sec 56.8%
redis(ioredis): 3941ms 25374ops/sec 46.1%
INCR:
redis(redis): 1564ms 63938ops/sec 100%
redis(thunk-redis): 1150ms 86956ops/sec 136.0%
redis(ioredis): 1816ms 55066ops/sec 86.1%
LPUSH:
redis(redis): 1357ms 73691ops/sec 100%
redis(thunk-redis): 1298ms 77041ops/sec 104.5%
redis(ioredis): 1799ms 55586ops/sec 75.4%
LRANGE 100:
redis(redis): 4888ms 20458ops/sec 100%
redis(thunk-redis): 9045ms 11055ops/sec 54.0%
redis(ioredis): 6553ms 15260ops/sec 74.6%
'use strict'
const thunk = require('thunks')()
const redis = require('..')
const nodeRedis = require('redis')
const IoRedis = require('ioredis')
// const co = require('co')
// test in thunks(thunk base)
thunk(bench)(console.log.bind(console))
// // test in co(promise base)
// co(bench)
// .then(console.log.bind(console))
// .catch(console.error.bind(console))
function * bench () {
var timeN = 0
var timeT = 0
var timeI = 0
var testLen = 100000
var titleN = 'redis(redis): '
var titleT = 'redis(thunk-redis):'
var titleI = 'redis(ioredis): '
var clientN = nodeRedis.createClient({port: 6379, db: 0})
var clientT = redis.createClient({port: 6379, db: 1})
var clientI = new IoRedis({port: 6379, db: 2, dropBufferSupport: true})
var queue = []
while (queue.length < testLen) queue.push(queue.length)
var smallStr = 'teambition'
var longStr = (new Array(4097).join('-'))
function printResult (title, timeN, timeT, timeI) {
console.log(`\n${title}:`)
console.log(titleN, `${timeN}ms`, Math.floor(testLen * 1000 / timeN) + 'ops/sec', '100%')
console.log(titleT, `${timeT}ms`, Math.floor(testLen * 1000 / timeT) + 'ops/sec', ((timeN / timeT) * 100).toFixed(1) + '%')
console.log(titleI, `${timeI}ms`, Math.floor(testLen * 1000 / timeI) + 'ops/sec', ((timeN / timeI) * 100).toFixed(1) + '%')
}
console.log(titleN + 'node_redis ', yield function (done) { clientN.flushdb(done) })
console.log(titleT + 'thunk-redis ', yield clientT.flushdb())
console.log(titleI + 'ioRedis ', yield clientI.flushdb())
console.log(`Bench start:(${testLen})\n`)
// PING concurrency(full thread)
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.ping(done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.ping()
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.ping()
})
timeI = Date.now() - timeI
printResult('PING concurrency(full thread)', timeN, timeT, timeI)
// PING concurrency(1000 thread)
yield thunk.delay(100)
timeN = Date.now()
yield function * () {
let count = queue.length
yield queue.slice(0, 1000).map(function () {
return next
})
function next (callback) {
if (count > 0) {
count--
clientN.ping(function (err) {
if (!err) next(callback)
else callback(err)
})
} else callback()
}
}
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield function * () {
let count = queue.length
yield queue.slice(0, 1000).map(function () {
return next
})
function next (callback) {
if (count > 0) {
count--
clientT.ping()(function (err) {
if (!err) next(callback)
else callback(err)
})
} else callback()
}
}
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield function * () {
let count = queue.length
yield queue.slice(0, 1000).map(function () {
return next
})
function next (callback) {
if (count > 0) {
count--
clientI.ping()
.then(function () {
next(callback)
})
.catch(callback)
} else callback()
}
}
timeI = Date.now() - timeI
printResult('PING concurrency(1000 thread)', timeN, timeT, timeI)
// PING sequential 1 by 1
yield thunk.delay(100)
timeN = Date.now()
for (let i = queue.length; i > 0; i--) {
yield function (done) { clientN.ping(done) }
}
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
for (let i = queue.length; i > 0; i--) {
yield clientT.ping()
}
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
for (let i = queue.length; i > 0; i--) {
yield clientI.ping()
}
timeI = Date.now() - timeI
printResult('PING sequential 1 by 1', timeN, timeT, timeI)
// SET small string
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.set('zensh_thunks_00000001', smallStr, done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.set('zensh_thunks_00000001', smallStr)
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.set('zensh_thunks_00000001', smallStr)
})
timeI = Date.now() - timeI
printResult('SET small string', timeN, timeT, timeI)
// GET small string
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.get('zensh_thunks_00000001', done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.get('zensh_thunks_00000001')
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.get('zensh_thunks_00000001')
})
timeI = Date.now() - timeI
printResult('GET small string', timeN, timeT, timeI)
// SET long string
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.set('zensh_thunks_00000002', longStr, done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.set('zensh_thunks_00000002', longStr)
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.set('zensh_thunks_00000002', longStr)
})
timeI = Date.now() - timeI
printResult('SET long string', timeN, timeT, timeI)
// GET long string
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.get('zensh_thunks_00000002', done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.get('zensh_thunks_00000002')
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.get('zensh_thunks_00000002')
})
timeI = Date.now() - timeI
printResult('GET long string', timeN, timeT, timeI)
// INCR
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.incr('zensh_thunks_00000003', done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.incr('zensh_thunks_00000003')
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.incr('zensh_thunks_00000003')
})
timeI = Date.now() - timeI
printResult('INCR', timeN, timeT, timeI)
// LPUSH
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.lpush('zensh_thunks_00000004', smallStr, done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.lpush('zensh_thunks_00000004', smallStr)
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.lpush('zensh_thunks_00000004', smallStr)
})
timeI = Date.now() - timeI
printResult('LPUSH', timeN, timeT, timeI)
// LRANGE
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.lrange('zensh_thunks_00000004', '0', '100', done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.lrange('zensh_thunks_00000004', '0', '100')
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.lrange('zensh_thunks_00000004', '0', '100')
})
timeI = Date.now() - timeI
printResult('LRANGE 100', timeN, timeT, timeI)
// yield thunk.delay(100)
yield function (done) { clientN.flushdb(done) }
yield clientT.flushdb()
yield clientI.flushdb()
process.exit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment