Permalink
Browse files

Use Uint8Array pool in browsers, just like node does with buffers

  • Loading branch information...
dcodeIO committed Dec 6, 2016
1 parent a46cc49 commit 7c28483d65cde148e61fe9993f1716960b39e049
Showing with 247 additions and 140 deletions.
  1. +11 −4 bench/prof.js
  2. +144 −105 dist/protobuf.js
  3. +1 −1 dist/protobuf.js.map
  4. +3 −3 dist/protobuf.min.js
  5. BIN dist/protobuf.min.js.gz
  6. +1 −1 dist/protobuf.min.js.map
  7. +1 −0 src/index.js
  8. +27 −0 src/pool.js
  9. +1 −1 src/reader.js
  10. +33 −24 src/writer.js
  11. +25 −1 types/protobuf.js.d.ts
@@ -6,21 +6,28 @@ var protobuf = require("..");
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 data = require("../bench/bench.json");
var count = process.argv.length > 3 && parseInt(process.argv[3]) || 10000000;
var count = process.argv.length > 3 && parseInt(process.argv[3], 10) || 10000000;
var r = protobuf.Reader.create(new Buffer(0));
function setupBrowser() {
protobuf.Writer.create = function create_browser() { return new protobuf.Writer(); };
protobuf.Reader.create = function create_browser(buf) { return new protobuf.Reader(buf); };
}
switch (process.argv[2]) {
default:
console.log("usage: " + path.basename(process.argv[1]) + " <encode|decode> [iterations=10000000]");
console.error("usage: " + path.basename(process.argv[1]) + " <encode|decode|encode-browser|decode-browser> [iterations=10000000]");
process.exit(1);
return;
case "encode-browser":
setupBrowser();
case "encode":
for (var i = 0; i < count; ++i)
Test.encode(data).finish();
break;
case "decode-browser":
setupBrowser();
case "decode":
var buf = Test.encode(data).finish();
for (var i = 0; i < count; ++i)
Oops, something went wrong.

0 comments on commit 7c28483

Please sign in to comment.