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