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('Encode packet'); rc-web@69: rc-web@69: suite.add('string', function () { rc-web@69: parser.encodePacket({ rc-web@69: type: 'json' rc-web@69: , endpoint: '' rc-web@69: , data: '2' rc-web@69: }); rc-web@69: }); rc-web@69: rc-web@69: suite.add('event', function () { rc-web@69: parser.encodePacket({ rc-web@69: type: 'event' rc-web@69: , name: 'woot' rc-web@69: , endpoint: '' rc-web@69: , args: [] rc-web@69: }); rc-web@69: }); rc-web@69: rc-web@69: suite.add('event+ack', function () { rc-web@69: parser.encodePacket({ rc-web@69: type: 'json' rc-web@69: , id: 1 rc-web@69: , ack: 'data' rc-web@69: , endpoint: '' rc-web@69: , data: { a: 'b' } rc-web@69: }); rc-web@69: }); rc-web@69: rc-web@69: suite.add('event+data', function () { rc-web@69: parser.encodePacket({ rc-web@69: type: 'event' rc-web@69: , name: 'edwald' rc-web@69: , endpoint: '' rc-web@69: , args: [{a: 'b'}, 2, '3'] rc-web@69: }); rc-web@69: }); rc-web@69: rc-web@69: suite.add('heartbeat', function () { rc-web@69: parser.encodePacket({ rc-web@69: type: 'heartbeat' rc-web@69: , endpoint: '' rc-web@69: }) rc-web@69: }); rc-web@69: rc-web@69: suite.add('error', function () { rc-web@69: parser.encodePacket({ rc-web@69: type: 'error' rc-web@69: , reason: 'unauthorized' rc-web@69: , advice: 'reconnect' rc-web@69: , endpoint: '' rc-web@69: }) rc-web@69: }) rc-web@69: rc-web@69: suite.add('payload', function () { rc-web@69: 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: 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: }