Sha256: ab13371fe60c9ab23c04dfaee8214e5f8ab3387f33fb83a33bb0524753769917

Contents?: true

Size: 1.86 KB

Versions: 181

Compression:

Stored size: 1.86 KB

Contents

var Benchmark = require('benchmark');
var parser = require('../index');

function test(packet, deferred) {
  var encoder = new parser.Encoder();
  var decoder = new parser.Decoder();
  encoder.encode(packet, function(encodedPackets) {
    var decoder = new parser.Decoder();
    decoder.on('decoded', function(packet) {
      deferred.resolve();
    });

    decoder.add(encodedPackets[0]);
  });
}

var dataObject = {
  'a': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
  'b': 'xxxyyyzzzalsdfalskdjfalksdjfalksdjfalksdjfjjfjfjfjjfjfjfj',
  'data': {
    'is': 'cool',
    'or': {
      'is': {
        'it': true
      }
    }
   }
};
var bigArray = [];
for (var i = 0; i < 250; i++) {
  bigArray.push(dataObject);
}



module.exports = function(callback) {
  var suite = new Benchmark.Suite();

  suite.add('small json parse', {defer: true, fn: function(deferred) {
    var packet = {
      type: parser.EVENT,
      nsp: '/bench',
      data: dataObject
    };
    test(packet, deferred);
  }})
  .add('big json parse', {defer: true, fn: function(deferred) {
    var packet = {
      type: parser.EVENT,
      nsp: '/bench',
      data: bigArray
    };
    test(packet, deferred);
  }})
  .add('json with small binary parse', {defer: true, fn: function(deferred) {
    var packet = {
      type: parser.EVENT,
      nsp: '/bench',
      data: {'a': [1, 2, 3], 'b': 'xxxyyyzzz', 'data': new Buffer(1000)}
    };
    test(packet, deferred);
  }})
  .add('json with big binary parse', {defer: true, fn: function(deferred) {
    var bigBinaryData = {
      bin1: new Buffer(10000),
      arr: bigArray,
      bin2: new Buffer(10000),
      bin3: new Buffer(10000)
    };
    var packet = {
      type: parser.EVENT,
      nsp: '/bench',
      data: bigBinaryData
    };
    test(packet, deferred);
  }})
  .on('complete', function() {
    callback(this);
  })
  .run({'async': true});
};

Version data entries

181 entries across 89 versions & 3 rubygems

Version Path
flok-0.0.90 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.89 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.89 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.88 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.88 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.87 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.87 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.86 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.86 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.85 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.85 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.84 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.84 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.83 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.83 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.82 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.82 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.81 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js
flok-0.0.81 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-parser/bench/index.js
flok-0.0.80 spec/iface/driver/assets/node_modules/socket.io/node_modules/socket.io-adapter/node_modules/socket.io-parser/bench/index.js