Skip to content

Commit 0643f93

Browse files
committed
Other: Some cleanup and added a logo
1 parent cba46c3 commit 0643f93

File tree

9 files changed

+71
-63
lines changed

9 files changed

+71
-63
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
protobuf.js
2-
===========
1+
# <p align="center"><img src="./pbjs.png" /></p>
2+
33
[![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]
44

55
**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 for: bench/alloc.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
var protobuf = require(".."),
2-
newSuite = require("./suite");
1+
/*eslint-disable no-new*//*global ArrayBuffer*/
2+
"use strict";
33

4-
var pool = require("../src/util/pool"),
5-
poolAlloc = pool(function(size) {
6-
return new Uint8Array(size);
7-
}, Uint8Array.prototype.subarray);
4+
var newSuite = require("./suite"),
5+
pool = require("../src/util/pool");
6+
7+
var poolAlloc = pool(function(size) {
8+
return new Uint8Array(size);
9+
}, Uint8Array.prototype.subarray);
810

911
[
1012
64,
@@ -15,30 +17,30 @@ var pool = require("../src/util/pool"),
1517

1618
newSuite("buffer[" + size + "]")
1719
.add("new Uint8Array", function() {
18-
var buf = new Uint8Array(size);
20+
new Uint8Array(size);
1921
})
2022
.add("Buffer.alloc", function() {
21-
var buf = Buffer.alloc(size);
23+
Buffer.alloc(size);
2224
})
2325
.add("poolAlloc<Uint8Array>", function() {
24-
var buf = poolAlloc(size);
26+
poolAlloc(size);
2527
})
2628
.add("Buffer.allocUnsafe", function() {
27-
var buf = Buffer.allocUnsafe(size);
29+
Buffer.allocUnsafe(size);
2830
})
2931
.add("new Buffer", function() {
30-
var buf = new Buffer(size);
32+
new Buffer(size);
3133
})
3234
.run();
3335

3436
var ab = new ArrayBuffer(size);
3537

3638
newSuite("wrap[" + size + "]")
3739
.add("new Uint8Array(ArrayBuffer)", function() {
38-
var buf = new Uint8Array(ab);
40+
new Uint8Array(ab);
3941
})
4042
.add("Buffer.from(ArrayBuffer)", function() {
41-
var buf = Buffer.from(ab);
43+
Buffer.from(ab);
4244
})
4345
.run();
4446

Diff for: bench/index.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
var protobuf = require(".."),
24
newSuite = require("./suite"),
35
data = require("./bench.json");
@@ -19,21 +21,22 @@ var protobuf = require(".."),
1921
//
2022
// To experience the impact by yourself, increase string lengths within bench.json.
2123

22-
var root = protobuf.loadSync(require.resolve("./bench.proto"));
23-
var Test = root.resolveAll().lookup("Test");
24+
var root = protobuf.loadSync(require.resolve("./bench.proto")),
25+
Test = root.resolveAll().lookup("Test");
2426

2527
// protobuf.util.codegen.verbose = true;
2628

2729
var buf = Test.encode(data).finish();
2830

2931
// warm up
30-
for (var i = 0; i < 500000; ++i)
32+
var i;
33+
for (i = 0; i < 500000; ++i)
3134
Test.encode(data).finish();
32-
for (var i = 0; i < 1000000; ++i)
35+
for (i = 0; i < 1000000; ++i)
3336
Test.decode(buf);
34-
for (var i = 0; i < 500000; ++i)
37+
for (i = 0; i < 500000; ++i)
3538
Test.verify(data);
36-
console.log("");
39+
process.stdout.write("\n");
3740

3841
if (!Buffer.from)
3942
Buffer.from = function from(str, enc) {
@@ -92,10 +95,13 @@ setTimeout(function() {
9295
var dataMessage = Test.from(data);
9396
var dataJson = dataMessage.asJSON();
9497

95-
newSuite("converting")
98+
newSuite("converting from JSON")
9699
.add("Message.from", function() {
97100
Test.from(dataJson);
98101
})
102+
.run();
103+
104+
newSuite("converting to JSON")
99105
.add("Message#asJSON", function() {
100106
dataMessage.asJSON();
101107
})

Diff for: bench/prof.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1+
"use strict";
2+
13
var fs = require("fs"),
24
path = require("path");
35

46
// A profiling stub to measure encoding / decoding performance using benchmark data.
57

68
var commands = ["encode", "decode", "encode-browser", "decode-browser"];
79
if (commands.indexOf(process.argv[2]) < 0) { // 0: node, 1: prof.js
8-
console.error("usage: " + path.basename(process.argv[1]) + " <" + commands.join('|') + "> [iterations=10000000]");
9-
process.exit(0);
10+
process.stderr.write("usage: " + path.basename(process.argv[1]) + " <" + commands.join("|") + "> [iterations=10000000]\n");
11+
return;
1012
}
1113

1214
// Spin up a node process with profiling enabled and process the generated log
1315
if (process.execArgv.indexOf("--prof") < 0) {
14-
console.log("cleaning up old logs ...");
16+
process.stdout.write("cleaning up old logs ...\n");
1517
var child_process = require("child_process");
16-
var logRe = /^isolate\-[0-9A-F]+\-v8\.log$/;
18+
var logRe = /^isolate-[0-9A-F]+-v8\.log$/;
1719
fs.readdirSync(process.cwd()).forEach(function readdirSync_it(file) {
1820
if (logRe.test(file))
1921
fs.unlink(file);
2022
});
21-
console.log("generating profile (may take a while) ...");
22-
var child = child_process.execSync("node --prof --trace-deopt " + process.execArgv.join(" ") + " " + process.argv.slice(1).join(' '), {
23+
process.stdout.write("generating profile (may take a while) ...\n");
24+
child_process.execSync("node --prof --trace-deopt " + process.execArgv.join(" ") + " " + process.argv.slice(1).join(' '), {
2325
cwd: process.cwd(),
24-
stdio: 'inherit'
26+
stdio: "inherit"
2527
});
26-
console.log("processing profile ...");
28+
process.stdout.write("processing profile ...\n");
2729
fs.readdirSync(process.cwd()).forEach(function readdirSync_it(file) {
2830
if (logRe.test(file)) {
2931
child_process.execSync("node --prof-process " + file, {
3032
cwd: process.cwd(),
31-
stdio: 'inherit'
33+
stdio: "inherit"
3234
});
3335
// fs.unlink(file);
3436
}
3537
});
36-
console.log("done.");
37-
process.exit(0);
38+
process.stdout.write("done.\n");
39+
return;
3840
}
3941

4042
// Actual profiling code
@@ -59,7 +61,7 @@ if (process.argv.indexOf("--alt") < 0) {
5961

6062
if (process.argv.length > 3 && /^\d+$/.test(process.argv[3]))
6163
count = parseInt(process.argv[3], 10);
62-
console.log(" x " + count);
64+
process.stdout.write(" x " + count + "\n");
6365

6466
function setupBrowser() {
6567
protobuf.Writer.create = function create_browser() { return new protobuf.Writer(); };
@@ -69,16 +71,17 @@ function setupBrowser() {
6971
switch (process.argv[2]) {
7072
case "encode-browser":
7173
setupBrowser();
74+
// eslint-disable-line no-fallthrough
7275
case "encode":
7376
for (var i = 0; i < count; ++i)
7477
Test.encode(data).finish();
7578
break;
7679
case "decode-browser":
7780
setupBrowser();
81+
// eslint-disable-line no-fallthrough
7882
case "decode":
7983
var buf = Test.encode(data).finish();
80-
for (var i = 0; i < count; ++i)
84+
for (var j = 0; j < count; ++j)
8185
Test.decode(buf);
8286
break;
8387
}
84-
process.exit(0);

Diff for: bench/read.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
var protobuf = require(".."),
2-
newSuite = require("./suite"),
1+
"use strict";
2+
var newSuite = require("./suite"),
33
ieee754 = require("../lib/ieee754");
44

55
// This benchmark compares raw data type performance of Uint8Array and Buffer.
66

77
var data = [ 0xCD, 0xCC, 0xCC, 0x3D ]; // ~0.10000000149011612 LE
8-
98
var array = new Uint8Array(data);
109
var buffer = Buffer.from(data);
1110

@@ -42,10 +41,9 @@ newSuite("float")
4241
})
4342
.run();
4443

45-
var data = [ 0x9A, 0x99, 0x99, 0x99, 0x99, 0x99, 0xB9, 0x3F ]; // 0.1 LE
46-
47-
var array = new Uint8Array(data);
48-
var buffer = Buffer.from(data);
44+
data = [ 0x9A, 0x99, 0x99, 0x99, 0x99, 0x99, 0xB9, 0x3F ]; // 0.1 LE
45+
array = new Uint8Array(data);
46+
buffer = Buffer.from(data);
4947

5048
// raw double read speed
5149
newSuite("double")
@@ -103,6 +101,7 @@ function readString(bytes) {
103101
}
104102
return String.fromCharCode.apply(String, out.slice(0, c));
105103
}
104+
return "";
106105
}
107106

108107
// raw string read speed

Diff for: bench/suite.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,25 @@ function newSuite(name) {
1313
benches.push(event.target);
1414
})
1515
.on("start", function() {
16-
console.log("benchmarking " + name + " performance ...\n");
17-
})
18-
.on("error", function(err) {
19-
console.log("ERROR:", err);
16+
process.stdout.write("benchmarking " + name + " performance ...\n\n");
2017
})
2118
.on("cycle", function(event) {
22-
console.log(String(event.target));
19+
process.stdout.write(String(event.target) + "\n");
2320
})
24-
.on("complete", function(event) {
21+
.on("complete", function() {
2522
if (benches.length > 1) {
26-
var fastest = this.filter('fastest'),
27-
slowest = this.filter('slowest');
28-
var fastestHz = getHz(fastest[0]);
29-
console.log("\n" + chalk.white(pad(fastest[0].name, padSize)) + " was " + chalk.green("fastest"));
23+
var fastest = this.filter("fastest"), // eslint-disable-line no-invalid-this
24+
fastestHz = getHz(fastest[0]);
25+
process.stdout.write("\n" + chalk.white(pad(fastest[0].name, padSize)) + " was " + chalk.green("fastest") + "\n");
3026
benches.forEach(function(bench) {
3127
if (fastest.indexOf(bench) === 0)
3228
return;
3329
var hz = hz = getHz(bench);
3430
var percent = (1 - (hz / fastestHz)) * 100;
35-
console.log(chalk.white(pad(bench.name, padSize)) + " was " + chalk.red(percent.toFixed(1)+'% slower'));
31+
process.stdout.write(chalk.white(pad(bench.name, padSize)) + " was " + chalk.red(percent.toFixed(1) + "% slower") + "\n");
3632
});
3733
}
38-
console.log();
34+
process.stdout.write("\n");
3935
});
4036
}
4137

Diff for: bench/write.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var protobuf = require(".."),
2-
newSuite = require("./suite"),
1+
"use strict";
2+
var newSuite = require("./suite"),
33
ieee754 = require("../lib/ieee754");
44

55
// This benchmark compares raw data type performance of Uint8Array and Buffer.
@@ -96,8 +96,8 @@ newSuite("double")
9696
.run();
9797

9898
var source = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
99-
var array = new Uint8Array(16);
100-
var buffer = new Buffer(16);
99+
array = new Uint8Array(16);
100+
buffer = new Buffer(16);
101101

102102
// raw bytes write speed
103103
newSuite("bytes")
@@ -143,7 +143,7 @@ function writeString(buf, pos, val) {
143143
}
144144
}
145145

146-
function byteLength(val) {
146+
/* function byteLength(val) {
147147
var strlen = val.length >>> 0;
148148
var len = 0;
149149
for (var i = 0; i < strlen; ++i) {
@@ -159,10 +159,10 @@ function byteLength(val) {
159159
len += 3;
160160
}
161161
return len;
162-
}
162+
} */
163163

164-
var array = new Uint8Array(1000);
165-
var buffer = new Buffer(1000);
164+
array = new Uint8Array(1000);
165+
buffer = new Buffer(1000);
166166

167167
[
168168
"Lorem ipsu",

Diff for: pbjs.png

3.69 KB
Loading

Diff for: src/parse.js

+2
Original file line numberDiff line numberDiff line change
@@ -667,5 +667,7 @@ function parse(source, root, options) {
667667
* @param {string} source Source contents
668668
* @param {ParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
669669
* @returns {ParserResult} Parser result
670+
* @property {string} filename=null Currently processing file name for error reporting, if known
671+
* @property {ParseOptions} defaults Default {@link ParseOptions}
670672
* @variation 2
671673
*/

0 commit comments

Comments
 (0)