From 0643f93f5c0d96ed0ece5b47f54993ac3a827f1b Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Tue, 3 Jan 2017 23:55:21 +0100 Subject: [PATCH] Other: Some cleanup and added a logo --- README.md | 4 ++-- bench/alloc.js | 28 +++++++++++++++------------- bench/index.js | 20 +++++++++++++------- bench/prof.js | 31 +++++++++++++++++-------------- bench/read.js | 13 ++++++------- bench/suite.js | 20 ++++++++------------ bench/write.js | 16 ++++++++-------- pbjs.png | Bin 0 -> 3778 bytes src/parse.js | 2 ++ 9 files changed, 71 insertions(+), 63 deletions(-) create mode 100644 pbjs.png diff --git a/README.md b/README.md index 7897f24e1..d191910ad 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -protobuf.js -=========== +#

+ [![travis][travis-image]][travis-url] [![david][david-image]][david-url] [![npm][npm-dl-image]][npm-url] [![npm][npm-image]][npm-url] [![donate][paypal-image]][paypal-url] **Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/)). diff --git a/bench/alloc.js b/bench/alloc.js index 18db244b3..d55c7f7c8 100644 --- a/bench/alloc.js +++ b/bench/alloc.js @@ -1,10 +1,12 @@ -var protobuf = require(".."), - newSuite = require("./suite"); +/*eslint-disable no-new*//*global ArrayBuffer*/ +"use strict"; -var pool = require("../src/util/pool"), - poolAlloc = pool(function(size) { - return new Uint8Array(size); - }, Uint8Array.prototype.subarray); +var newSuite = require("./suite"), + pool = require("../src/util/pool"); + +var poolAlloc = pool(function(size) { + return new Uint8Array(size); +}, Uint8Array.prototype.subarray); [ 64, @@ -15,19 +17,19 @@ var pool = require("../src/util/pool"), newSuite("buffer[" + size + "]") .add("new Uint8Array", function() { - var buf = new Uint8Array(size); + new Uint8Array(size); }) .add("Buffer.alloc", function() { - var buf = Buffer.alloc(size); + Buffer.alloc(size); }) .add("poolAlloc", function() { - var buf = poolAlloc(size); + poolAlloc(size); }) .add("Buffer.allocUnsafe", function() { - var buf = Buffer.allocUnsafe(size); + Buffer.allocUnsafe(size); }) .add("new Buffer", function() { - var buf = new Buffer(size); + new Buffer(size); }) .run(); @@ -35,10 +37,10 @@ var pool = require("../src/util/pool"), newSuite("wrap[" + size + "]") .add("new Uint8Array(ArrayBuffer)", function() { - var buf = new Uint8Array(ab); + new Uint8Array(ab); }) .add("Buffer.from(ArrayBuffer)", function() { - var buf = Buffer.from(ab); + Buffer.from(ab); }) .run(); diff --git a/bench/index.js b/bench/index.js index 847e64610..35159ce64 100644 --- a/bench/index.js +++ b/bench/index.js @@ -1,3 +1,5 @@ +"use strict"; + var protobuf = require(".."), newSuite = require("./suite"), data = require("./bench.json"); @@ -19,21 +21,22 @@ var protobuf = require(".."), // // To experience the impact by yourself, increase string lengths within bench.json. -var root = protobuf.loadSync(require.resolve("./bench.proto")); -var Test = root.resolveAll().lookup("Test"); +var root = protobuf.loadSync(require.resolve("./bench.proto")), + Test = root.resolveAll().lookup("Test"); // protobuf.util.codegen.verbose = true; var buf = Test.encode(data).finish(); // warm up -for (var i = 0; i < 500000; ++i) +var i; +for (i = 0; i < 500000; ++i) Test.encode(data).finish(); -for (var i = 0; i < 1000000; ++i) +for (i = 0; i < 1000000; ++i) Test.decode(buf); -for (var i = 0; i < 500000; ++i) +for (i = 0; i < 500000; ++i) Test.verify(data); -console.log(""); +process.stdout.write("\n"); if (!Buffer.from) Buffer.from = function from(str, enc) { @@ -92,10 +95,13 @@ setTimeout(function() { var dataMessage = Test.from(data); var dataJson = dataMessage.asJSON(); - newSuite("converting") + newSuite("converting from JSON") .add("Message.from", function() { Test.from(dataJson); }) + .run(); + + newSuite("converting to JSON") .add("Message#asJSON", function() { dataMessage.asJSON(); }) diff --git a/bench/prof.js b/bench/prof.js index a2402cf1b..e389db75a 100644 --- a/bench/prof.js +++ b/bench/prof.js @@ -1,3 +1,5 @@ +"use strict"; + var fs = require("fs"), path = require("path"); @@ -5,36 +7,36 @@ var fs = require("fs"), var commands = ["encode", "decode", "encode-browser", "decode-browser"]; if (commands.indexOf(process.argv[2]) < 0) { // 0: node, 1: prof.js - console.error("usage: " + path.basename(process.argv[1]) + " <" + commands.join('|') + "> [iterations=10000000]"); - process.exit(0); + process.stderr.write("usage: " + path.basename(process.argv[1]) + " <" + commands.join("|") + "> [iterations=10000000]\n"); + return; } // Spin up a node process with profiling enabled and process the generated log if (process.execArgv.indexOf("--prof") < 0) { - console.log("cleaning up old logs ..."); + process.stdout.write("cleaning up old logs ...\n"); var child_process = require("child_process"); - var logRe = /^isolate\-[0-9A-F]+\-v8\.log$/; + var logRe = /^isolate-[0-9A-F]+-v8\.log$/; fs.readdirSync(process.cwd()).forEach(function readdirSync_it(file) { if (logRe.test(file)) fs.unlink(file); }); - console.log("generating profile (may take a while) ..."); - var child = child_process.execSync("node --prof --trace-deopt " + process.execArgv.join(" ") + " " + process.argv.slice(1).join(' '), { + process.stdout.write("generating profile (may take a while) ...\n"); + child_process.execSync("node --prof --trace-deopt " + process.execArgv.join(" ") + " " + process.argv.slice(1).join(' '), { cwd: process.cwd(), - stdio: 'inherit' + stdio: "inherit" }); - console.log("processing profile ..."); + process.stdout.write("processing profile ...\n"); fs.readdirSync(process.cwd()).forEach(function readdirSync_it(file) { if (logRe.test(file)) { child_process.execSync("node --prof-process " + file, { cwd: process.cwd(), - stdio: 'inherit' + stdio: "inherit" }); // fs.unlink(file); } }); - console.log("done."); - process.exit(0); + process.stdout.write("done.\n"); + return; } // Actual profiling code @@ -59,7 +61,7 @@ if (process.argv.indexOf("--alt") < 0) { if (process.argv.length > 3 && /^\d+$/.test(process.argv[3])) count = parseInt(process.argv[3], 10); -console.log(" x " + count); +process.stdout.write(" x " + count + "\n"); function setupBrowser() { protobuf.Writer.create = function create_browser() { return new protobuf.Writer(); }; @@ -69,16 +71,17 @@ function setupBrowser() { switch (process.argv[2]) { case "encode-browser": setupBrowser(); + // eslint-disable-line no-fallthrough case "encode": for (var i = 0; i < count; ++i) Test.encode(data).finish(); break; case "decode-browser": setupBrowser(); + // eslint-disable-line no-fallthrough case "decode": var buf = Test.encode(data).finish(); - for (var i = 0; i < count; ++i) + for (var j = 0; j < count; ++j) Test.decode(buf); break; } -process.exit(0); diff --git a/bench/read.js b/bench/read.js index 6ed3be5c4..fc4bf8b3e 100644 --- a/bench/read.js +++ b/bench/read.js @@ -1,11 +1,10 @@ -var protobuf = require(".."), - newSuite = require("./suite"), +"use strict"; +var newSuite = require("./suite"), ieee754 = require("../lib/ieee754"); // This benchmark compares raw data type performance of Uint8Array and Buffer. var data = [ 0xCD, 0xCC, 0xCC, 0x3D ]; // ~0.10000000149011612 LE - var array = new Uint8Array(data); var buffer = Buffer.from(data); @@ -42,10 +41,9 @@ newSuite("float") }) .run(); -var data = [ 0x9A, 0x99, 0x99, 0x99, 0x99, 0x99, 0xB9, 0x3F ]; // 0.1 LE - -var array = new Uint8Array(data); -var buffer = Buffer.from(data); +data = [ 0x9A, 0x99, 0x99, 0x99, 0x99, 0x99, 0xB9, 0x3F ]; // 0.1 LE +array = new Uint8Array(data); +buffer = Buffer.from(data); // raw double read speed newSuite("double") @@ -103,6 +101,7 @@ function readString(bytes) { } return String.fromCharCode.apply(String, out.slice(0, c)); } + return ""; } // raw string read speed diff --git a/bench/suite.js b/bench/suite.js index 728fd9bd3..f6bdeabc1 100644 --- a/bench/suite.js +++ b/bench/suite.js @@ -13,29 +13,25 @@ function newSuite(name) { benches.push(event.target); }) .on("start", function() { - console.log("benchmarking " + name + " performance ...\n"); - }) - .on("error", function(err) { - console.log("ERROR:", err); + process.stdout.write("benchmarking " + name + " performance ...\n\n"); }) .on("cycle", function(event) { - console.log(String(event.target)); + process.stdout.write(String(event.target) + "\n"); }) - .on("complete", function(event) { + .on("complete", function() { if (benches.length > 1) { - var fastest = this.filter('fastest'), - slowest = this.filter('slowest'); - var fastestHz = getHz(fastest[0]); - console.log("\n" + chalk.white(pad(fastest[0].name, padSize)) + " was " + chalk.green("fastest")); + var fastest = this.filter("fastest"), // eslint-disable-line no-invalid-this + fastestHz = getHz(fastest[0]); + process.stdout.write("\n" + chalk.white(pad(fastest[0].name, padSize)) + " was " + chalk.green("fastest") + "\n"); benches.forEach(function(bench) { if (fastest.indexOf(bench) === 0) return; var hz = hz = getHz(bench); var percent = (1 - (hz / fastestHz)) * 100; - console.log(chalk.white(pad(bench.name, padSize)) + " was " + chalk.red(percent.toFixed(1)+'% slower')); + process.stdout.write(chalk.white(pad(bench.name, padSize)) + " was " + chalk.red(percent.toFixed(1) + "% slower") + "\n"); }); } - console.log(); + process.stdout.write("\n"); }); } diff --git a/bench/write.js b/bench/write.js index fc31f83df..811c528c8 100644 --- a/bench/write.js +++ b/bench/write.js @@ -1,5 +1,5 @@ -var protobuf = require(".."), - newSuite = require("./suite"), +"use strict"; +var newSuite = require("./suite"), ieee754 = require("../lib/ieee754"); // This benchmark compares raw data type performance of Uint8Array and Buffer. @@ -96,8 +96,8 @@ newSuite("double") .run(); var source = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); -var array = new Uint8Array(16); -var buffer = new Buffer(16); +array = new Uint8Array(16); +buffer = new Buffer(16); // raw bytes write speed newSuite("bytes") @@ -143,7 +143,7 @@ function writeString(buf, pos, val) { } } -function byteLength(val) { +/* function byteLength(val) { var strlen = val.length >>> 0; var len = 0; for (var i = 0; i < strlen; ++i) { @@ -159,10 +159,10 @@ function byteLength(val) { len += 3; } return len; -} +} */ -var array = new Uint8Array(1000); -var buffer = new Buffer(1000); +array = new Uint8Array(1000); +buffer = new Buffer(1000); [ "Lorem ipsu", diff --git a/pbjs.png b/pbjs.png new file mode 100644 index 0000000000000000000000000000000000000000..ed67df68c6892e4ed3ca88e2666bdb58350ee447 GIT binary patch literal 3778 zcmV;z4n6USP)ne&!g=KYJkbNWaghc_q+eIGq({gmkSc%k4QNL zl4uD@v_z=E(3lrb>ewl42lnUVg;Jv%0g2S^qZTDiclctY!C*K_+x5+xH|OmDNpyJO z1|oPbZI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