Skip to content

Commit

Permalink
Use Uint8Array pool in browsers, just like node does with buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 6, 2016
1 parent a46cc49 commit 7c28483
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 140 deletions.
15 changes: 11 additions & 4 deletions bench/prof.js
Expand Up @@ -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)
Expand Down

0 comments on commit 7c28483

Please sign in to comment.