-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plain js utf8 is faster for short strings
- Loading branch information
Showing
12 changed files
with
167 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var benchmark = require("benchmark"), | ||
chalk = require("chalk"); | ||
|
||
var padSize = 27; | ||
|
||
module.exports = function newSuite(name) { | ||
var benches = []; | ||
return new benchmark.Suite(name) | ||
.on("add", function(event) { | ||
benches.push(event.target); | ||
}) | ||
.on("start", function() { | ||
console.log("benchmarking " + name + " performance ...\n"); | ||
}) | ||
.on("error", function(err) { | ||
console.log("ERROR:", err); | ||
}) | ||
.on("cycle", function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", function(event) { | ||
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")); | ||
benches.forEach(function(bench) { | ||
if (fastest.indexOf(bench) > -1) | ||
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')); | ||
}); | ||
console.log(); | ||
}); | ||
} | ||
|
||
function getHz(bench) { | ||
return 1 / (bench.stats.mean + bench.stats.moe); | ||
} | ||
|
||
function pad(str, len, l) { | ||
while (str.length < len) | ||
str = l ? str + " " : " " + str; | ||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var protobuf = require("../src/index"), | ||
newSuite = require("./suite"); | ||
|
||
newSuite("float") | ||
.add("Writer#float", function() { | ||
var writer = new protobuf.Writer(); | ||
writer.float(0.1); | ||
writer.finish(); | ||
}) | ||
.add("BufferWriter#float", function() { | ||
var writer = new protobuf.BufferWriter(); | ||
writer.float(0.1); | ||
writer.finish(); | ||
}) | ||
.run(); | ||
|
||
newSuite("double") | ||
.add("Writer#double", function() { | ||
var writer = new protobuf.Writer(); | ||
writer.double(0.1); | ||
writer.finish(); | ||
}) | ||
.add("BufferWriter#double", function() { | ||
var writer = new protobuf.BufferWriter(); | ||
writer.double(0.1); | ||
writer.finish(); | ||
}) | ||
.run(); | ||
|
||
var bytes = [0, 0, 0, 0, 0, 0, 0, 0]; | ||
var arrayBytes = new Uint8Array(bytes); | ||
var bufferBytes = Buffer.from(bytes); | ||
|
||
newSuite("bytes") | ||
.add("Writer#bytes", function() { | ||
var writer = new protobuf.Writer(); | ||
writer.bytes(arrayBytes); | ||
writer.finish(); | ||
}) | ||
.add("BufferWriter#bytes", function() { | ||
var writer = new protobuf.BufferWriter(); | ||
writer.bytes(bufferBytes); | ||
writer.finish(); | ||
}) | ||
.run(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.