Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added decode/encode benchmarks

  • Loading branch information...
commit f8c7ff2782e7922b47b4ce6bed6e8e0046195938 1 parent 175fe85
@tj tj authored
View
1  .gitignore
@@ -6,4 +6,5 @@ lib-cov
*.dat
*.out
*.pid
+benchmarks/*.png
node_modules
View
7 Makefile
@@ -19,4 +19,9 @@ test-cov:
test-leaks:
@ls test/leaks/* | xargs node --expose_debug_as=debug --expose_gc
-.PHONY: test
+bench:
+ @node benchmarks/encode \
+ && node benchmarks/decode \
+ && open benchmarks/{encode,decode}.png
+
+.PHONY: test bench
View
52 benchmarks/decode.js
@@ -0,0 +1,52 @@
+
+/**
+ * Module dependencies.
+ */
+
+var vbench = require('vbench')
+ , io = require('../')
+ , parser = io.parser;
+
+console.log(' decode:');
+
+var suite = vbench.createSuite({
+ path: __dirname + '/decode.png'
+ , min: 500
+});
+
+suite.bench('string', function(next){
+ parser.decodePacket('4:::"2"');
+ next();
+});
+
+suite.bench('event', function(next){
+ parser.decodePacket('5:::{"name":"woot"}');
+ next()
+});
+
+suite.bench('event+ack', function(next){
+ parser.decodePacket('5:1+::{"name":"tobi"}');
+ next();
+});
+
+suite.bench('event+data', function(next){
+ parser.decodePacket('5:::{"name":"edwald","args":[{"a": "b"},2,"3"]}');
+ next();
+});
+
+var payload = parser.encodePayload([
+ parser.encodePacket({ type: 'message', data: '5', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: '53d', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobarbazfoobarbaz', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
+]);
+
+suite.bench('payload', function(next){
+ parser.decodePayload(payload);
+ next();
+});
+
+suite.run();
View
70 benchmarks/encode.js
@@ -0,0 +1,70 @@
+
+/**
+ * Module dependencies.
+ */
+
+var vbench = require('vbench')
+ , io = require('../')
+ , parser = io.parser;
+
+console.log('\n encode:');
+
+var suite = vbench.createSuite({
+ path: __dirname + '/encode.png'
+ , min: 500
+});
+
+suite.bench('string', function(next){
+ parser.encodePacket({
+ type: 'json'
+ , endpoint: ''
+ , data: '2'
+ })
+ next();
+});
+
+suite.bench('event', function(next){
+ parser.encodePacket({
+ type: 'event'
+ , name: 'woot'
+ , endpoint: ''
+ , args: []
+ });
+ next();
+});
+
+suite.bench('event+ack', function(next){
+ parser.encodePacket({
+ type: 'json'
+ , id: 1
+ , ack: 'data'
+ , endpoint: ''
+ , data: { a: 'b' }
+ });
+ next();
+});
+
+suite.bench('event+data', function(next){
+ parser.encodePacket({
+ type: 'event'
+ , name: 'edwald'
+ , endpoint: ''
+ , args: [{a: 'b'}, 2, '3']
+ });
+ next();
+});
+
+suite.bench('payload', function(next){
+ parser.encodePayload([
+ parser.encodePacket({ type: 'message', data: '5', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: '53d', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobarbazfoobarbaz', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
+ , parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
+ ]);
+ next();
+});
+
+suite.run();
View
1  package.json
@@ -24,6 +24,7 @@
"expresso": "0.7.7"
, "should": "0.0.4"
, "assertvanish": "0.0.3-1"
+ , "vbench": "0.0.2"
}
, "main": "index"
, "engines": { "node": ">= 0.4.0" }
Please sign in to comment.
Something went wrong with that request. Please try again.