Created
August 17, 2020 00:19
-
-
Save jhuckaby/9e27a039fc8309427a4163e23bfacc85 to your computer and use it in GitHub Desktop.
Benchmarks for pixl-pack vs msgpack-lite
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
var msgpack = require("msgpack-lite"); | |
var pack = require('pixl-pack'); | |
var tests = [ | |
[ "Null", null ], | |
[ "Boolean", true ], | |
[ "String", "Now is the time for all good men to come to the aid of their country." ], | |
[ "Buffer", Buffer.from("Now is the time for all good men to come to the aid of their country.") ], | |
[ "Number", 12345.67890 ], | |
[ "Object", { foo: "bar", "num": 123 } ], | |
[ "Array", [ 0, 1, 2, 3, 4, 5 ] ] | |
]; | |
var rows = []; | |
tests.forEach( function(test) { | |
var test_name = test[0]; | |
var test_data = test[1]; | |
var row = [ test_name ]; | |
console.log("Running test: " + test_name + "..."); | |
var time_start = Date.now(); | |
var done = false; | |
var count = 0; | |
while (!done) { | |
var buf = msgpack.encode(test_data); | |
var data = msgpack.decode(buf); | |
count++; | |
if (Date.now() - time_start >= 1000) done = true; | |
} | |
row.push( count + " /sec" ); | |
time_start = Date.now(); | |
done = false; | |
count = 0; | |
while (!done) { | |
var buf = pack.encode(test_data); | |
var data = pack.decode(buf); | |
count++; | |
if (Date.now() - time_start >= 1000) done = true; | |
} | |
row.push( count + " /sec" ); | |
rows.push( row ); | |
}); | |
console.log( '' ); | |
console.log( `| Test | msgpack-lite | pixl-pack |` ); | |
console.log( `|------|--------------|-----------|` ); | |
rows.forEach( function(row) { | |
console.log( "| " + row.join(" | ") + " |" ); | |
} ); | |
console.log( '' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment