annotate node_modules/socket.io/benchmarks/encode.bench.js @ 69:333afcfd3f3a

added node_modules to project and fixed path to chronometer also added deps to installer script
author tzara <rc-web@kiben.net>
date Sat, 26 Oct 2013 14:12:50 +0100
parents
children
rev   line source
rc-web@69 1
rc-web@69 2 /**
rc-web@69 3 * Module dependencies.
rc-web@69 4 */
rc-web@69 5
rc-web@69 6 var benchmark = require('benchmark')
rc-web@69 7 , colors = require('colors')
rc-web@69 8 , io = require('../')
rc-web@69 9 , parser = io.parser
rc-web@69 10 , suite = new benchmark.Suite('Encode packet');
rc-web@69 11
rc-web@69 12 suite.add('string', function () {
rc-web@69 13 parser.encodePacket({
rc-web@69 14 type: 'json'
rc-web@69 15 , endpoint: ''
rc-web@69 16 , data: '2'
rc-web@69 17 });
rc-web@69 18 });
rc-web@69 19
rc-web@69 20 suite.add('event', function () {
rc-web@69 21 parser.encodePacket({
rc-web@69 22 type: 'event'
rc-web@69 23 , name: 'woot'
rc-web@69 24 , endpoint: ''
rc-web@69 25 , args: []
rc-web@69 26 });
rc-web@69 27 });
rc-web@69 28
rc-web@69 29 suite.add('event+ack', function () {
rc-web@69 30 parser.encodePacket({
rc-web@69 31 type: 'json'
rc-web@69 32 , id: 1
rc-web@69 33 , ack: 'data'
rc-web@69 34 , endpoint: ''
rc-web@69 35 , data: { a: 'b' }
rc-web@69 36 });
rc-web@69 37 });
rc-web@69 38
rc-web@69 39 suite.add('event+data', function () {
rc-web@69 40 parser.encodePacket({
rc-web@69 41 type: 'event'
rc-web@69 42 , name: 'edwald'
rc-web@69 43 , endpoint: ''
rc-web@69 44 , args: [{a: 'b'}, 2, '3']
rc-web@69 45 });
rc-web@69 46 });
rc-web@69 47
rc-web@69 48 suite.add('heartbeat', function () {
rc-web@69 49 parser.encodePacket({
rc-web@69 50 type: 'heartbeat'
rc-web@69 51 , endpoint: ''
rc-web@69 52 })
rc-web@69 53 });
rc-web@69 54
rc-web@69 55 suite.add('error', function () {
rc-web@69 56 parser.encodePacket({
rc-web@69 57 type: 'error'
rc-web@69 58 , reason: 'unauthorized'
rc-web@69 59 , advice: 'reconnect'
rc-web@69 60 , endpoint: ''
rc-web@69 61 })
rc-web@69 62 })
rc-web@69 63
rc-web@69 64 suite.add('payload', function () {
rc-web@69 65 parser.encodePayload([
rc-web@69 66 parser.encodePacket({ type: 'message', data: '5', endpoint: '' })
rc-web@69 67 , parser.encodePacket({ type: 'message', data: '53d', endpoint: '' })
rc-web@69 68 , parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
rc-web@69 69 , parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
rc-web@69 70 , parser.encodePacket({ type: 'message', data: 'foobarbazfoobarbaz', endpoint: '' })
rc-web@69 71 , parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
rc-web@69 72 , parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
rc-web@69 73 ]);
rc-web@69 74 });
rc-web@69 75
rc-web@69 76 suite.on('cycle', function (bench, details) {
rc-web@69 77 console.log('\n' + suite.name.grey, details.name.white.bold);
rc-web@69 78 console.log([
rc-web@69 79 details.hz.toFixed(2).cyan + ' ops/sec'.grey
rc-web@69 80 , details.count.toString().white + ' times executed'.grey
rc-web@69 81 , 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey
rc-web@69 82 ,
rc-web@69 83 ].join(', '.grey));
rc-web@69 84 });
rc-web@69 85
rc-web@69 86 if (!module.parent) {
rc-web@69 87 suite.run();
rc-web@69 88 } else {
rc-web@69 89 module.exports = suite;
rc-web@69 90 }