folz / bento

:bento: A fast, correct, pure-Elixir library for reading and writing Bencoded metainfo (.torrent) files.
Mozilla Public License 2.0
95 stars 14 forks source link

Implement `Bento.Decoder.transform/2` #24

Closed mogeko closed 1 year ago

mogeko commented 1 year ago

Replace the old Posison.Decode.decode/2 with Bento.Decoder.transform/2.

As you can see, the benchmark shows that there is no obvious difference in performance.

Earlier times:

## ParserBench
benchmark name      iterations   average time 
single (Bencodex)       500000   4.02 µs/op
single (Bento)          500000   6.36 µs/op
single (bencode)        100000   16.51 µs/op
multi (Bencodex)          5000   666.52 µs/op
multi (Bento)             1000   1110.96 µs/op
single (bencoder)         1000   1276.72 µs/op
multi (bencode)           1000   1941.72 µs/op
multi (bencoder)           500   7130.18 µs/op

Nowadays:

## ParserBench
benchmark name      iterations   average time 
single (Bencodex)       500000   4.24 µs/op
single (Bento)          500000   6.36 µs/op
single (bencode)        100000   14.28 µs/op
multi (Bencodex)          2000   603.69 µs/op
multi (Bento)             1000   1148.87 µs/op
single (bencoder)         1000   1511.96 µs/op
multi (bencode)           1000   1732.82 µs/op
multi (bencoder)           500   6760.21 µs/op

At this stage, I need to write some additional unit tests and documents to check if I have missed anything.

Moreover, I encapsulated Bento.Parser by the way.

folz commented 1 year ago

Caught up from your comment https://github.com/folz/bento/pull/15#issuecomment-1416881549 - this also sounds good to me. LMK when you're ready if you'd like a review!