rc-web@69: rc-web@69: /** rc-web@69: * Module dependencies. rc-web@69: */ rc-web@69: rc-web@69: var benchmark = require('benchmark') rc-web@69: , colors = require('colors') rc-web@69: , io = require('../') rc-web@69: , parser = io.parser rc-web@69: , suite = new benchmark.Suite('Decode packet'); rc-web@69: rc-web@69: suite.add('string', function () { rc-web@69: parser.decodePacket('4:::"2"'); rc-web@69: }); rc-web@69: rc-web@69: suite.add('event', function () { rc-web@69: parser.decodePacket('5:::{"name":"woot"}'); rc-web@69: }); rc-web@69: rc-web@69: suite.add('event+ack', function () { rc-web@69: parser.decodePacket('5:1+::{"name":"tobi"}'); rc-web@69: }); rc-web@69: rc-web@69: suite.add('event+data', function () { rc-web@69: parser.decodePacket('5:::{"name":"edwald","args":[{"a": "b"},2,"3"]}'); rc-web@69: }); rc-web@69: rc-web@69: suite.add('heartbeat', function () { rc-web@69: parser.decodePacket('2:::'); rc-web@69: }); rc-web@69: rc-web@69: suite.add('error', function () { rc-web@69: parser.decodePacket('7:::2+0'); rc-web@69: }); rc-web@69: rc-web@69: var payload = parser.encodePayload([ rc-web@69: parser.encodePacket({ type: 'message', data: '5', endpoint: '' }) rc-web@69: , parser.encodePacket({ type: 'message', data: '53d', endpoint: '' }) rc-web@69: , parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' }) rc-web@69: , parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' }) rc-web@69: , parser.encodePacket({ type: 'message', data: 'foobarbazfoobarbaz', endpoint: '' }) rc-web@69: , parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' }) rc-web@69: , parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' }) rc-web@69: ]); rc-web@69: rc-web@69: suite.add('payload', function () { rc-web@69: parser.decodePayload(payload); rc-web@69: }); rc-web@69: rc-web@69: suite.on('cycle', function (bench, details) { rc-web@69: console.log('\n' + suite.name.grey, details.name.white.bold); rc-web@69: console.log([ rc-web@69: details.hz.toFixed(2).cyan + ' ops/sec'.grey rc-web@69: , details.count.toString().white + ' times executed'.grey rc-web@69: , 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey rc-web@69: , rc-web@69: ].join(', '.grey)); rc-web@69: }); rc-web@69: rc-web@69: if (!module.parent) { rc-web@69: suite.run(); rc-web@69: } else { rc-web@69: module.exports = suite; rc-web@69: }