agronholm / cbor2

Python CBOR (de)serializer with extensive tag support
MIT License
217 stars 57 forks source link

Trade-offs between cbor and cbor2 #158

Closed cheqianh closed 1 year ago

cheqianh commented 1 year ago

Hello!

I am new to cbor and recently looking into cbor and cbor2, and having a question about what benefits cbor2 brings that cbor does not have?

I experimented on their dumps/loads APIs with some sample data (E.g. a 64 bits integer, an alphabet string). In short, cbor uses less memory and usually runs faster.

My guess is that cbor2 implements RFC 8949 while cbor is still targeting RFC 7049? Is there any benefits cbor2 brings that cbor does not have? Please feel free to correct me or point out a documentation that I've missed.

cheqianh commented 1 year ago

One example,

Benchmark:

import time
import cbor
import cbor2

o = 9233720363654371807

start = time.time()
for i in range(1000000):
    cbor.dumps(o)  
print(time.time() - start)
Results cbor cbor2
0.85502s 2.9855s
agronholm commented 1 year ago

cbor has not been maintained since 2016. It also segfaults on self referential structures, and does not implement any tag support. In short, it cuts corners which, I believe, is why it's faster.

cheqianh commented 1 year ago

Alright, thanks for the response!