Comparing version 0.4.2 to 0.5.0
@@ -7,8 +7,14 @@ Here are more comprehensive benchmarks. This is comparison with the next fastest JS projects using the benchmark tool from `msgpack-lite` (and data is from some clinical research data we use that has a good mix of different value types and structures). It also includes comparison to V8 native JSON functionality, and JavaScript Avro (`avsc`, a very optimized Avro implementation): | ||
obj = JSON.parse(buf); | 88600 | 5000 | 17720 | ||
require("msgpackr").pack(obj); | 161500 | 5002 | 32287 | ||
require("msgpackr").unpack(buf); | 94600 | 5004 | 18904 | ||
msgpackr w/ shared structures: packr.pack(obj); | 178400 | 5002 | 35665 | ||
msgpackr w/ shared structures: packr.unpack(buf); | 376700 | 5000 | 75340 | ||
require("cbor-x").encode(obj); | 161500 | 5002 | 32287 | ||
require("cbor-x").decode(buf); | 94600 | 5004 | 18904 | ||
cbor-x w/ shared structures: encoder.encode(obj); | 178400 | 5002 | 35665 | ||
cbor-x w/ shared structures: encoder.decode(buf); | 376700 | 5000 | 75340 | ||
buf = require("cbor").encode(obj); | 7700 | 5008 | 1537 | ||
obj = require("cbor").decode(buf); | 3100 | 5119 | 605 | ||
buf = require("cbor-sync").encode(obj); | 18000 | 5025 | 3582 | ||
obj = require("cbor-sync").decode(buf); | 20900 | 5011 | 4170 | ||
buf = require("msgpack-lite").encode(obj); | 30100 | 5012 | 6005 | ||
obj = require("msgpack-lite").decode(buf); | 16200 | 5001 | 3239 | ||
buf = require("@msgpack/msgpack").encode(obj); | 101200 | 5001 | 20235 | ||
obj = require("@msgpack/msgpack").decode(buf); | 71200 | 5004 | 14228 | ||
buf = require("notepack").encode(obj); | 62600 | 5005 | 12507 | ||
@@ -21,18 +27,18 @@ obj = require("notepack").decode(buf); | 32400 | 5007 | 6470 | ||
(`avsc` is schema-based and more comparable in style to msgpackr with shared structures). | ||
(`avsc` is schema-based and more comparable in style to cbor-x with shared structures). | ||
Here is a benchmark of streaming data (again borrowed from `msgpack-lite`'s benchmarking), where msgpackr is able to take advantage of the structured record extension and really pull away from other tools: | ||
Here is a benchmark of streaming data (again borrowed from `msgpack-lite`'s benchmarking), where cbor-x is able to take advantage of the structured record extension and really pull away from other tools: | ||
operation (1000000 x 2) | op | ms | op/s | ||
------------------------------------------------ | ------: | ----: | -----: | ||
new PackrStream().write(obj); | 1000000 | 372 | 2688172 | ||
new UnpackrStream().write(buf); | 1000000 | 247 | 4048582 | ||
stream.write(msgpack.encode(obj)); | 1000000 | 2898 | 345065 | ||
stream.write(msgpack.decode(buf)); | 1000000 | 1969 | 507872 | ||
stream.write(notepack.encode(obj)); | 1000000 | 901 | 1109877 | ||
stream.write(notepack.decode(buf)); | 1000000 | 1012 | 988142 | ||
msgpack.Encoder().on("data",ondata).encode(obj); | 1000000 | 1763 | 567214 | ||
msgpack.createDecodeStream().write(buf); | 1000000 | 2222 | 450045 | ||
msgpack.createEncodeStream().write(obj); | 1000000 | 1577 | 634115 | ||
msgpack.Decoder().on("data",ondata).decode(buf); | 1000000 | 2246 | 445235 | ||
new EncoderStream().write(obj); | 1000000 | 533 | 1876172 | ||
new DecoderStream().write(buf); | 1000000 | 297 | 3367003 | ||
stream.write(msgpack.encode(obj)); | 1000000 | 3179 | 314564 | ||
stream.write(msgpack.decode(buf)); | 1000000 | 2151 | 464900 | ||
stream.write(notepack.encode(obj)); | 1000000 | 944 | 1059322 | ||
stream.write(notepack.decode(buf)); | 1000000 | 1131 | 884173 | ||
msgpack.Encoder().on("data",ondata).encode(obj); | 1000000 | 1687 | 592768 | ||
msgpack.createDecodeStream().write(buf); | 1000000 | 2084 | 479846 | ||
msgpack.createEncodeStream().write(obj); | 1000000 | 1475 | 677966 | ||
msgpack.Decoder().on("data",ondata).decode(buf); | 1000000 | 2264 | 441696 | ||
@@ -49,3 +55,3 @@ | ||
msgpack-js | 967,682 ops/sec | 184,455 ops/sec | 20,556 ops/sec | 259 ops/sec | ||
msgpackr | 2,392,826 ops/sec | 556,915 ops/sec | 70,573 ops/sec | 313 ops/sec | ||
cbor-x | 2,392,826 ops/sec | 556,915 ops/sec | 70,573 ops/sec | 313 ops/sec | ||
msgpack-lite | 553,143 ops/sec | 132,318 ops/sec | 11,816 ops/sec | 186 ops/sec | ||
@@ -61,8 +67,8 @@ @msgpack/msgpack | 2,157,655 ops/sec | 573,236 ops/sec | 25,864 ops/sec | 90.26 ops/sec | ||
msgpack-js | 965,719 ops/sec | 222,047 ops/sec | 21,431 ops/sec | 257 ops/sec | ||
msgpackr | 2,320,046 ops/sec | 589,167 ops/sec | 70,299 ops/sec | 329 ops/sec | ||
msgpackr records | 3,750,547 ops/sec | 912,419 ops/sec | 136,853 ops/sec | 733 ops/sec | ||
cbor-x | 2,320,046 ops/sec | 589,167 ops/sec | 70,299 ops/sec | 329 ops/sec | ||
cbor-x records | 3,750,547 ops/sec | 912,419 ops/sec | 136,853 ops/sec | 733 ops/sec | ||
msgpack-lite | 569,222 ops/sec | 129,008 ops/sec | 12,424 ops/sec | 180 ops/sec | ||
@msgpack/msgpack | 2,089,697 ops/sec | 557,507 ops/sec | 20,256 ops/sec | 85.03 ops/sec | ||
This was run by adding the msgpackr to the benchmarks for notepack. | ||
This was run by adding the cbor-x to the benchmarks for notepack. | ||
@@ -69,0 +75,0 @@ All benchmarks were performed on Node 14.8.0 (Windows i7-4770 3.4Ghz). They can be run with: |
@@ -11,2 +11,4 @@ "use strict" | ||
const EMPTY_ARRAY = [] | ||
const RECORD_STARTING_ID_PREFIX = 0x9d | ||
const RECORD_STARTING_ID = 40100 | ||
let strings = EMPTY_ARRAY | ||
@@ -180,4 +182,4 @@ let stringPosition = 0 | ||
case 6: // extension | ||
if (token >= 0x40 && token < 0x100) { // record structures | ||
let structure = currentStructures[token - 0x40] | ||
if ((token >> 8) == RECORD_STARTING_ID_PREFIX) { // record structures | ||
let structure = currentStructures[token & 0xff] | ||
if (structure) { | ||
@@ -197,3 +199,3 @@ if (!structure.read) | ||
currentStructures.splice.apply(currentStructures, [0, updatedStructures.length].concat(updatedStructures)) | ||
structure = currentStructures[token - 0x40] | ||
structure = currentStructures[token & 0xff] | ||
if (structure) { | ||
@@ -208,4 +210,9 @@ if (!structure.read) | ||
} else { | ||
if (currentExtensions[token]) | ||
return currentExtensions[token](read()) | ||
let extension = currentExtensions[token] | ||
if (extension) { | ||
if (extension.handlesRead) | ||
return extension(read) | ||
else | ||
return extension(read()) | ||
} | ||
else | ||
@@ -235,10 +242,12 @@ throw new Error('Unknown extension ' + token) | ||
function createStructureReader(structure) { | ||
let l = structure.length | ||
function readObject() { | ||
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function | ||
if (readObject.count++ > 2) { | ||
this.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read) | ||
this.read = (new Function('a', 'r', 'return function(){a();return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(readArrayHeader, read) | ||
return this.read() | ||
} | ||
readArrayHeader(l) | ||
let object = {} | ||
for (let i = 0, l = structure.length; i < l; i++) { | ||
for (let i = 0; i < l; i++) { | ||
let key = structure[i] | ||
@@ -253,2 +262,18 @@ object[key] = read() | ||
function readArrayHeader(expectedLength) { | ||
// consume the array header, TODO: check expected length | ||
let token = src[position++] | ||
//let majorType = token >> 5 | ||
token = token & 0x1f | ||
if (token > 0x17) { | ||
switch (token) { | ||
case 0x18: position++ | ||
break | ||
case 0x19: position += 2 | ||
break | ||
case 0x1a: position += 4 | ||
} | ||
} | ||
} | ||
let readFixedString = readStringJS | ||
@@ -560,15 +585,18 @@ let readString8 = readStringJS | ||
// the registration of the record definition extension (tag 6) | ||
currentExtensions[6] = (structure) => { | ||
let id = structure[0] | ||
structure = structure.slice(1) | ||
currentStructures[id - 0x40] = structure | ||
const recordDefinition = () => { | ||
readArrayHeader(3) | ||
let id = read() | ||
let structure = read() | ||
currentStructures[id & 0xff] = structure | ||
structure.read = createStructureReader(structure) | ||
return structure.read() | ||
} | ||
recordDefinition.handlesRead = true | ||
currentExtensions[40006] = recordDefinition | ||
currentExtensions[8] = (data) => { | ||
currentExtensions[40008] = (data) => { | ||
return (glbl[data[0]] || Error)(data[1]) | ||
} | ||
currentExtensions[9] = (id) => { | ||
currentExtensions[40009] = (id) => { | ||
// id extension (for structured clones) | ||
@@ -595,3 +623,3 @@ if (!referenceMap) | ||
currentExtensions[10] = (id) => { | ||
currentExtensions[40010] = (id) => { | ||
// pointer extension (for structured clones) | ||
@@ -603,7 +631,7 @@ let refEntry = referenceMap.get(id) | ||
currentExtensions[11] = (array) => new Set(array) | ||
currentExtensions[40011] = (array) => new Set(array) | ||
const typedArrays = ['Int8','Uint8 ','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array') | ||
currentExtensions[12] = (data) => { | ||
currentExtensions[40012] = (data) => { | ||
let [ typeCode, buffer ] = data | ||
@@ -616,3 +644,3 @@ let typedArrayName = typedArrays[typeCode] | ||
} | ||
currentExtensions[13] = (data) => { | ||
currentExtensions[40013] = (data) => { | ||
return new RegExp(data[0], data[1]) | ||
@@ -619,0 +647,0 @@ } |
145
encode.js
@@ -14,2 +14,4 @@ "use strict" | ||
const ByteArray = hasNodeBuffer ? Buffer : Uint8Array | ||
const RECORD_STARTING_ID_PREFIX = 0x9d | ||
const MAX_STRUCTURES = 0x100 | ||
let target | ||
@@ -91,3 +93,3 @@ let targetView | ||
} | ||
transition[RECORD_SYMBOL] = i + 0x40 | ||
transition[RECORD_SYMBOL] = i | ||
} | ||
@@ -97,3 +99,3 @@ lastSharedStructuresLength = sharedStructures.length | ||
if (!isSequential) | ||
sharedStructures.nextId = sharedStructuresLength + 0x40 | ||
sharedStructures.nextId = sharedStructuresLength | ||
} | ||
@@ -107,3 +109,3 @@ if (hasSharedUpdate) | ||
if (referenceMap && referenceMap.idsToInsert) { | ||
position += referenceMap.idsToInsert.length * 6 | ||
position += referenceMap.idsToInsert.length * 8 | ||
if (position > safeEnd) | ||
@@ -290,3 +292,5 @@ makeRoom(position) | ||
} | ||
target[position++] = 0xca // tag 10 | ||
target[position++] = 0xd9 | ||
target[position++] = 40010 >> 8 | ||
target[position++] = 40010 & 0xff | ||
target[position++] = 0x1a // uint32 | ||
@@ -306,13 +310,4 @@ targetView.setUint32(position, referee.id) | ||
target[position++] = 0x80 | length | ||
} else if (length < 0x100) { | ||
target[position++] = 0x98 | ||
target[position++] = length | ||
} else if (length < 0x10000) { | ||
target[position++] = 0x99 | ||
target[position++] = length >> 8 | ||
target[position++] = length & 0xff | ||
} else { | ||
target[position++] = 0x9a | ||
targetView.setUint32(position, length) | ||
position += 4 | ||
writeArrayHeader(length) | ||
} | ||
@@ -358,3 +353,3 @@ for (let i = 0; i < length; i++) { | ||
} else if (tag > -1) { | ||
target[position++] = 0xba | ||
target[position++] = 0xda | ||
targetView.setUint32(position, tag) | ||
@@ -471,3 +466,4 @@ position += 4 | ||
let newTransitions = 0 | ||
for (let i =0, l = keys.length; i < l; i++) { | ||
let length = keys.length | ||
for (let i =0; i < length; i++) { | ||
let key = keys[i] | ||
@@ -483,3 +479,4 @@ nextTransition = transition[key] | ||
if (recordId) { | ||
target[position++] = 0xd8 // tag one byte | ||
target[position++] = 0xd9 // tag two byte | ||
target[position++] = RECORD_STARTING_ID_PREFIX | ||
target[position++] = recordId | ||
@@ -489,27 +486,39 @@ } else { | ||
if (!recordId) { | ||
recordId = 0x40 | ||
structures.nextId = 0x41 | ||
recordId = 0 | ||
structures.nextId = 1 | ||
} | ||
if (recordId >= 0x100) {// cycle back around | ||
structures.nextId = (recordId = maxSharedStructures + 0x40) + 1 | ||
if (recordId >= MAX_STRUCTURES) {// cycle back around | ||
structures.nextId = (recordId = maxSharedStructures) + 1 | ||
} | ||
transition[RECORD_SYMBOL] = recordId | ||
structures[recordId - 0x40] = keys | ||
structures[recordId] = keys | ||
if (sharedStructures && sharedStructures.length <= maxSharedStructures) { | ||
target[position++] = 0xd8 // tag one byte | ||
target[position++] = 0xd9 // tag two byte | ||
target[position++] = RECORD_STARTING_ID_PREFIX | ||
target[position++] = recordId // tag number | ||
hasSharedUpdate = true | ||
} else { | ||
target[position++] = 0xc6 // tag 6 | ||
target[position++] = 0xd9 | ||
target[position++] = 40006 >> 8 | ||
target[position++] = 40006 & 0xff | ||
if (newTransitions) | ||
transitionsCount += serializationsSinceTransitionRebuild * newTransitions | ||
// record the removal of the id, we can maintain our shared structure | ||
if (recordIdsToRemove.length >= 0xc0 - maxSharedStructures) | ||
if (recordIdsToRemove.length >= MAX_STRUCTURES - maxSharedStructures) | ||
recordIdsToRemove.shift()[RECORD_SYMBOL] = 0 // we are cycling back through, and have to remove old ones | ||
recordIdsToRemove.push(transition) | ||
encode([ recordId ].concat(keys)) | ||
target[position++] = 0x83 // array header, length 3 | ||
target[position++] = 0x19 // uint16 | ||
target[position++] = RECORD_STARTING_ID_PREFIX | ||
target[position++] = recordId | ||
encode(keys) | ||
} | ||
} | ||
if (length < 0x18) { // write the array header | ||
target[position++] = 0x80 | length | ||
} else { | ||
writeArrayHeader(length) | ||
} | ||
// now write the values | ||
for (let i =0, l = keys.length; i < l; i++) | ||
for (let i =0; i < length; i++) | ||
encode(object[keys[i]]) | ||
@@ -546,2 +555,17 @@ } | ||
function writeArrayHeader(length) { | ||
if (length < 0x100) { | ||
target[position++] = 0x98 | ||
target[position++] = length | ||
} else if (length < 0x10000) { | ||
target[position++] = 0x99 | ||
target[position++] = length >> 8 | ||
target[position++] = length & 0xff | ||
} else { | ||
target[position++] = 0x9a | ||
targetView.setUint32(position, length) | ||
position += 4 | ||
} | ||
} | ||
extensionClasses = [ Date, Set, Error, RegExp, ArrayBuffer, Object.getPrototypeOf(Uint8Array.prototype).constructor /*TypedArray*/ ] | ||
@@ -565,3 +589,3 @@ extensions = [{ | ||
}, { | ||
tag: 11, | ||
tag: 40011, | ||
encode(set, encode) { | ||
@@ -572,3 +596,3 @@ let array = Array.from(set) | ||
}, { | ||
tag: 8, | ||
tag: 40008, | ||
encode(error, encode) { | ||
@@ -578,3 +602,3 @@ encode([ error.name, error.message ]) | ||
}, { | ||
tag: 13, | ||
tag: 40013, | ||
encode(regex, encode) { | ||
@@ -601,3 +625,5 @@ encode([ regex.source, regex.flags ]) | ||
function writeExtBuffer(typedArray, type, encode) { | ||
target[position++] = 0xcc // tag 12 | ||
target[position++] = 0xd9 | ||
target[position++] = 40012 >> 8 | ||
target[position++] = 40012 & 0xff | ||
let length = typedArray.byteLength | ||
@@ -630,49 +656,6 @@ let offset = typedArray.byteOffset || 0 | ||
function writeExtensionData(result, target, position, type) { | ||
let length = result.length | ||
switch (length) { | ||
case 1: | ||
target[position++] = 0xd4 | ||
break | ||
case 2: | ||
target[position++] = 0xd5 | ||
break | ||
case 4: | ||
target[position++] = 0xd6 | ||
break | ||
case 8: | ||
target[position++] = 0xd7 | ||
break | ||
case 16: | ||
target[position++] = 0xd8 | ||
break | ||
default: | ||
if (length < 0x100) { | ||
target[position++] = 0xc7 | ||
target[position++] = length | ||
} else if (length < 0x10000) { | ||
target[position++] = 0xc8 | ||
target[position++] = length << 8 | ||
target[position++] = length & 0xff | ||
} else { | ||
target[position++] = 0xc9 | ||
target[position++] = length << 24 | ||
target[position++] = (length << 16) & 0xff | ||
target[position++] = (length << 8) & 0xff | ||
target[position++] = length & 0xff | ||
} | ||
} | ||
target[position++] = type | ||
if (result.copy) | ||
result.copy(target, position) | ||
else | ||
copyBinary(result, target, position, 0, length) | ||
position += length | ||
return position | ||
} | ||
function insertIds(serialized, idsToInsert) { | ||
// insert the ids that need to be referenced for structured clones | ||
let nextId | ||
let distanceToMove = idsToInsert.length * 6 | ||
let distanceToMove = idsToInsert.length * 8 | ||
let lastEnd = serialized.length - distanceToMove | ||
@@ -684,9 +667,11 @@ idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1) | ||
serialized.copyWithin(offset + distanceToMove, offset, lastEnd) | ||
distanceToMove -= 6 | ||
distanceToMove -= 8 | ||
let position = offset + distanceToMove | ||
serialized[position++] = 0xc9 // tag 9 | ||
serialized[position++] = 0xd9 | ||
serialized[position++] = 40009 >> 8 | ||
serialized[position++] = 40009 & 0xff | ||
serialized[position++] = 0x1a // uint32 | ||
serialized[position++] = id << 24 | ||
serialized[position++] = (id << 16) & 0xff | ||
serialized[position++] = (id << 8) & 0xff | ||
serialized[position++] = id >> 24 | ||
serialized[position++] = (id >> 16) & 0xff | ||
serialized[position++] = (id >> 8) & 0xff | ||
serialized[position++] = id & 0xff | ||
@@ -693,0 +678,0 @@ lastEnd = offset |
{ | ||
"name": "cbor-x", | ||
"author": "Kris Zyp", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"license": "MIT", | ||
@@ -32,3 +32,5 @@ "types": "./index.d.ts", | ||
"devDependencies": { | ||
"async": "^3", | ||
"cbor": "^5", | ||
"cbor-sync": "^1.0.4", | ||
"@types/node": "latest", | ||
@@ -35,0 +37,0 @@ "chai": "^4", |
@@ -152,14 +152,16 @@ # cbor-x | ||
---------------------------------------------------------- | ------: | ----: | -----: | ||
buf = Buffer(JSON.stringify(obj)); | 75900 | 5003 | 15170 | ||
obj = JSON.parse(buf); | 90800 | 5002 | 18152 | ||
require("cbor-x").encode(obj); | 158400 | 5000 | 31680 | ||
require("cbor-x").decode(buf); | 99200 | 5003 | 19828 | ||
cbor-x w/ shared structures: encoder.encode(obj); | 183400 | 5002 | 36665 | ||
cbor-x w/ shared structures: encoder.decode(buf); | 415000 | 5000 | 83000 | ||
buf = require("msgpack-lite").encode(obj); | 30600 | 5005 | 6113 | ||
obj = require("msgpack-lite").decode(buf); | 15900 | 5030 | 3161 | ||
buf = require("@msgpack/msgpack").encode(obj); | 101200 | 5001 | 20235 | ||
obj = require("@msgpack/msgpack").decode(buf); | 71200 | 5004 | 14228 | ||
buf = require("notepack").encode(obj); | 65300 | 5006 | 13044 | ||
obj = require("notepack").decode(buf); | 32300 | 5001 | 6458 | ||
buf = Buffer(JSON.stringify(obj)); | 78200 | 5004 | 15627 | ||
obj = JSON.parse(buf); | 89600 | 5003 | 17909 | ||
require("cbor-x").encode(obj); | 163100 | 5001 | 32613 | ||
require("cbor-x").decode(buf); | 100200 | 5004 | 20023 | ||
cbor-x w/ shared structures: packr.encode(obj); | 178300 | 5002 | 35645 | ||
cbor-x w/ shared structures: packr.decode(buf); | 414000 | 5000 | 82800 | ||
buf = require("cbor").encode(obj); | 7800 | 5016 | 1555 | ||
obj = require("cbor").decode(buf); | 3200 | 5087 | 629 | ||
buf = require("cbor-sync").encode(obj); | 18600 | 5012 | 3711 | ||
obj = require("cbor-sync").decode(buf); | 20000 | 5020 | 3984 | ||
buf = require("msgpack-lite").encode(obj); | 30900 | 5013 | 6163 | ||
obj = require("msgpack-lite").decode(buf); | 15800 | 5012 | 3152 | ||
buf = require("notepack").encode(obj); | 62600 | 5006 | 12504 | ||
obj = require("notepack").decode(buf); | 33700 | 5007 | 6730 | ||
require("avsc")...make schema/type...type.toBuffer(obj); | 86900 | 5002 | 17373 | ||
@@ -218,4 +220,7 @@ require("avsc")...make schema/type...type.fromBuffer(obj); | 106100 | 5000 | 21220 | ||
## Extensions | ||
Cbor-x uses tag ids 40000 to 40500 for its extensions. | ||
## Record Structure Extension Definition | ||
The record struction extension uses tag 6 to declare a new record structure. This is followed by an array where the first byte indicates the tag of the record structure and the remaining elements are the field names. The record tag id must be from 0x40 - 0xff (and therefore replaces one byte representations of positive integers 64 - 255, which can alternately be represented with int or uint types). The extension declaration must be immediately follow by the field names of the record structure. | ||
The record struction extension uses tag 40006 to declare a new record structure. This is followed by an array where the first byte indicates the tag id of the record structure to declare and the next element is an array of the field names, and the third element is array of the property values. The extension declaration must be immediately follow by the field names of the record structure. | ||
@@ -230,3 +235,3 @@ ### Dates | ||
The high-performance serialization and deserialization algorithms in the msgpackr package are also available in the [msgpackr](https://github.com/kriszyp/msgpackr) for the MessagePack format, with the same API and design. A quick summary of the pros and cons of using MessagePack vs CBOR are: | ||
* MessagePack has wider adoption, and, at least with this implementation is slightly more efficient (by roughly 1%). | ||
* MessagePack has wider adoption, and, at least with this implementation is slightly more efficient (by roughly 2-4%). | ||
* CBOR has an [official IETF standardization track](https://tools.ietf.org/html/rfc7049), and the record extensions is conceptually/philosophically a better fit for CBOR tags. | ||
@@ -233,0 +238,0 @@ |
@@ -6,3 +6,3 @@ #!/usr/bin/env node | ||
let { PackrStream, UnpackrStream } = require(".."); | ||
let { EncoderStream, DecoderStream } = require(".."); | ||
var msgpack = require("msgpack-lite"); | ||
@@ -25,3 +25,3 @@ var Encoder = require("msgpack-lite/lib/encoder").Encoder; | ||
var blocksToJoin = [] | ||
var streamForJoin = new PackrStream(); | ||
var streamForJoin = new EncoderStream(); | ||
streamForJoin.on("data", data => blocksToJoin.push(data)); | ||
@@ -43,4 +43,4 @@ for (var j = 0; j < joincount; j++) { | ||
var list = [ | ||
['new PackrStream().write(obj);', encode5], | ||
['new UnpackrStream().write(buf);', decode5], | ||
['new EncoderStream().write(obj);', encode5], | ||
['new DecoderStream().write(buf);', decode5], | ||
['stream.write(msgpack.encode(obj));', encode1], | ||
@@ -59,3 +59,3 @@ ['stream.write(msgpack.decode(buf));', decode1], | ||
function encode5(callback) { | ||
var stream = new PackrStream(); | ||
var stream = new EncoderStream(); | ||
var cnt = counter(callback); | ||
@@ -122,3 +122,3 @@ stream.on("data", cnt.inc); | ||
function decode5(callback) { | ||
var stream = new UnpackrStream(); | ||
var stream = new DecoderStream(); | ||
var cnt = counter(callback); | ||
@@ -125,0 +125,0 @@ stream.on("data", cnt.inc); |
@@ -14,2 +14,3 @@ var cborX = tryRequire(".."); | ||
var cbor = tryRequire('cbor') | ||
var cborSync = tryRequire('cbor-sync') | ||
@@ -61,6 +62,5 @@ msgpack5 = msgpack5 && msgpack5(); | ||
encoder = new cborX.Encoder({ structures: [] }) | ||
buf = bench('cbor-x w/ shared structures: packr.encode(obj);', encoder.encode.bind(encoder), data); | ||
// buf = bench('msgpackr w/ shared structures: packr.pack(obj);', data => {let result = packr.pack(data); packr.resetMemory(); return result;}, data); | ||
buf = bench('cbor-x w/ shared structures: encoder.encode(obj);', encoder.encode.bind(encoder), data); | ||
obj = bench('cbor-x w/ shared structures: packr.decode(buf);', encoder.decode.bind(encoder), buf); | ||
obj = bench('cbor-x w/ shared structures: encoder.decode(buf);', encoder.decode.bind(encoder), buf); | ||
test(obj); | ||
@@ -132,2 +132,3 @@ } | ||
} | ||
if (cbor) { | ||
@@ -138,2 +139,7 @@ buf = bench('buf = require("cbor").encode(obj);', cbor.encode, data); | ||
} | ||
if (cborSync) { | ||
buf = bench('buf = require("cbor-sync").encode(obj);', cborSync.encode, data); | ||
obj = bench('obj = require("cbor-sync").decode(buf);', cborSync.decode, buf); | ||
test(obj); | ||
} | ||
@@ -140,0 +146,0 @@ function JSON_stringify(src) { |
@@ -258,3 +258,3 @@ //var inspector = require('inspector') | ||
var serialized = encoder.encode(data) | ||
assert.equal(serialized.length, 32) | ||
assert.equal(serialized.length, 37) | ||
var deserialized = encoder.decode(serialized) | ||
@@ -261,0 +261,0 @@ assert.deepEqual(deserialized, data) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
216950
2762
246
9