Skip to content

Instantly share code, notes, and snippets.

@nashibao
Created April 17, 2014 09:47
Show Gist options
  • Save nashibao/10969533 to your computer and use it in GitHub Desktop.
Save nashibao/10969533 to your computer and use it in GitHub Desktop.
dnode performance.
dnode = require 'dnode'
async = require 'async'
iteration_num = 100
# setup
server = dnode {
test: (a, b, cb)->
cb(null, a + b)
}
server.listen(8062)
# dnode ---------------------
d = dnode.connect(8062)
d.on 'remote', (client)->
test = (i, cb)->
client.test 1, 2, (err, result)->
cb(null, 0)
start = new Date().getTime()
async.map [0..iteration_num], test, (err, results)->
end = new Date().getTime()
sec = end - start
console.log 'latency:', sec, 'ms'
# results:
# 100 -> 14ms
# 1000 -> 70ms
# 10,000 -> 660ms
# 100,000 -> 36404ms
# local ---------------------
test = (i, cb)->
cb(null, 1 + 2)
start = new Date().getTime()
async.map [0..iteration_num], test, (err, results)->
end = new Date().getTime()
sec = end - start
console.log 'latency:', sec, 'ms'
# results:
# 100 -> 0ms
# 1000 -> 1ms
# 10,000 -> 4ms
# 100,000 -> 40ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment