Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance #17

Closed
rynop opened this issue Jun 8, 2017 · 3 comments
Closed

performance #17

rynop opened this issue Jun 8, 2017 · 3 comments

Comments

@rynop
Copy link

rynop commented Jun 8, 2017

Have you happen to have done any performance analysis of using this lib to encode/decode cbor vs encoding/decoing JSON?

Similar to what Paul Irish did for cbor in browser paroga/cbor-js#11

If it has not already been done, I'm happy to write tests.

@rynop
Copy link
Author

rynop commented Jun 9, 2017

I ended up just writing a test. borc vs https://github.com/hildjj/node-cbor vs JSON.

JSON encode/decode is significantly faster. Is this just because the cbor encode/decode is happening in pure JS? If not, what is the benefit/selling point of using cbor?

If cbor is not required, and if binary xfer is not required, what is the benefit of cbor when working in IoT environment? If working in IoT, I would think most data payloads would already be small, so size of JSON vs cbor is not a factor IMO.

Output:

~ $ node perf.js
cbor: 5.976ms
cbor: 0.625ms
cbor: 2.188ms
cbor: 0.603ms
cbor: 4.759ms
cbor: 0.598ms
cbor: 2.905ms
cbor: 3.946ms

borc: 4.721ms
borc: 0.442ms
borc: 0.332ms
borc: 0.163ms
borc: 0.318ms
borc: 0.252ms
borc: 0.201ms
borc: 1.284ms

JSON: 0.035ms
JSON: 0.013ms
JSON: 0.053ms
JSON: 0.017ms
JSON: 0.015ms
JSON: 0.080ms
JSON: 0.012ms
JSON: 0.014ms

@dignifiedquire
Copy link
Owner

Thank you, if you check the benchmarks they compare to JSON.stringify and parse as well

rynop added a commit to rynop/borc that referenced this issue Jun 14, 2017
@rynop
Copy link
Author

rynop commented Jun 14, 2017

fwiw iMac 5k got following results on the benchmarks included in this repo. Needed to add benchmark dev dependency in PR above.

~/projects/borc (master|✔) $ npm run bench

> [email protected] bench /Users/ryan/projects/borc
> node benchmarks/index

PID: 34298
encode - node-cbor - 74 x 433 ops/sec ±3.47% (64 runs sampled)
encode - borc - 74 x 12,970 ops/sec ±1.66% (91 runs sampled)
encode - stream - borc - 74 x 4,781 ops/sec ±6.34% (80 runs sampled)
encode - JSON.stringify - 74 x 36,658 ops/sec ±6.35% (81 runs sampled)
decode - node-cbor - 45 x 556 ops/sec ±2.79% (81 runs sampled)
decode - borc - 45 x 17,192 ops/sec ±4.97% (80 runs sampled)
decode - JSON.parse - 45 x 47,713 ops/sec ±15.52% (54 runs sampled)

@rynop rynop closed this as completed Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants