Permalink
Browse files

Removed as-function overload for Reader/Writer, profiler stub, optimi…

…zed version of Reader#int32
  • Loading branch information...
dcodeIO committed Dec 6, 2016
1 parent 53a16bf commit a46cc4934b7e888ae80e06fd7fdf91e5bc7f54f5
@@ -368,33 +368,33 @@ The package includes a [benchmark](https://github.com/dcodeIO/protobuf.js/tree/m
```
benchmarking encoding performance ...
Type.encode to buffer x 469,818 ops/sec ±0.58% (89 runs sampled)
JSON.stringify to string x 309,883 ops/sec ±0.81% (92 runs sampled)
JSON.stringify to buffer x 174,440 ops/sec ±1.46% (87 runs sampled)
Type.encode to buffer x 471,717 ops/sec ±1.30% (91 runs sampled)
JSON.stringify to string x 310,406 ops/sec ±1.00% (90 runs sampled)
JSON.stringify to buffer x 172,766 ops/sec ±1.20% (84 runs sampled)
Type.encode to buffer was fastest
JSON.stringify to string was 34.2% slower
JSON.stringify to buffer was 63.2% slower
JSON.stringify to string was 34.0% slower
JSON.stringify to buffer was 63.3% slower
benchmarking decoding performance ...
Type.decode from buffer x 1,127,271 ops/sec ±0.76% (90 runs sampled)
JSON.parse from string x 295,445 ops/sec ±0.74% (92 runs sampled)
JSON.parse from buffer x 265,703 ops/sec ±0.85% (92 runs sampled)
Type.decode from buffer x 1,285,867 ops/sec ±0.70% (90 runs sampled)
JSON.parse from string x 292,106 ops/sec ±1.00% (89 runs sampled)
JSON.parse from buffer x 259,361 ops/sec ±0.92% (90 runs sampled)
Type.decode from buffer was fastest
JSON.parse from string was 73.8% slower
JSON.parse from buffer was 76.4% slower
JSON.parse from string was 77.4% slower
JSON.parse from buffer was 79.9% slower
benchmarking combined performance ...
Type to/from buffer x 232,255 ops/sec ±0.99% (87 runs sampled)
JSON to/from string x 125,555 ops/sec ±1.01% (91 runs sampled)
JSON to/from buffer x 91,243 ops/sec ±0.83% (91 runs sampled)
Type to/from buffer x 238,382 ops/sec ±0.96% (89 runs sampled)
JSON to/from string x 127,352 ops/sec ±0.73% (93 runs sampled)
JSON to/from buffer x 89,593 ops/sec ±0.85% (87 runs sampled)
Type to/from buffer was fastest
JSON to/from string was 46.0% slower
JSON to/from buffer was 60.7% slower
JSON to/from string was 46.5% slower
JSON to/from buffer was 62.4% slower
```
Note that JSON is a native binding nowadays and as such is *really* fast. So, how can protobuf.js be faster?
@@ -0,0 +1,29 @@
var fs = require("fs"),
path = require("path");
var protobuf = require("..");
// A profiling stub to measure just raw encoding / decoding performance using benchmark data.
var root = protobuf.parse(fs.readFileSync(require.resolve("../bench/bench.proto")).toString("utf8")).root;
var Test = root.lookup("Test");
var data = data = require("../bench/bench.json");
var count = process.argv.length > 3 && parseInt(process.argv[3]) || 10000000;
var r = protobuf.Reader.create(new Buffer(0));
switch (process.argv[2]) {
default:
console.log("usage: " + path.basename(process.argv[1]) + " <encode|decode> [iterations=10000000]");
process.exit(1);
return;
case "encode":
for (var i = 0; i < count; ++i)
Test.encode(data).finish();
break;
case "decode":
var buf = Test.encode(data).finish();
for (var i = 0; i < count; ++i)
Test.decode(buf);
break;
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +8 Bytes (100%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -21,7 +21,7 @@ var Enum = require("./enum"),
decoder.fallback = function fallback(reader, length) {
/* eslint-disable no-invalid-this, block-scoped-var, no-redeclare */
var fields = this.getFieldsById(),
reader = reader instanceof Reader ? reader : Reader(reader),
reader = reader instanceof Reader ? reader : Reader.create(reader),
limit = length === undefined ? reader.len : reader.pos + length,
message = new (this.getCtor())();
while (reader.pos < limit) {
@@ -92,7 +92,7 @@ decoder.generate = function generate(mtype) {
var fields = mtype.getFieldsArray();
var gen = util.codegen("r", "l")
("r instanceof Reader||(r=Reader(r))")
("r instanceof Reader||(r=Reader.create(r))")
("var c=l===undefined?r.len:r.pos+l,m=new(this.getCtor())")
("while(r.pos<c){")
("var t=r.tag()")
@@ -21,7 +21,7 @@ var Enum = require("./enum"),
encoder.fallback = function fallback(message, writer) {
/* eslint-disable block-scoped-var, no-redeclare */
if (!writer)
writer = Writer();
writer = Writer.create();
var fields = this.getFieldsArray(), fi = 0;
while (fi < fields.length) {
var field = fields[fi++].resolve(),
@@ -99,7 +99,7 @@ encoder.generate = function generate(mtype) {
/* eslint-disable no-unexpected-multiline */
var fields = mtype.getFieldsArray();
var gen = util.codegen("m", "w")
("w||(w=Writer())");
("w||(w=Writer.create())");
for (var i = 0; i < fields.length; ++i) {
var field = fields[i].resolve(),
Oops, something went wrong.

0 comments on commit a46cc49

Please sign in to comment.