Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Use String.build instead of IO::Memory.#5

Open
didactic-drunk wants to merge 4 commits intonoumar:masterfrom
didactic-drunk:new_encode
Open

Use String.build instead of IO::Memory.#5
didactic-drunk wants to merge 4 commits intonoumar:masterfrom
didactic-drunk:new_encode

Conversation

@didactic-drunk
Copy link

New faster implementation of Base32.encode.
Correctly handle NUL bytes.
Add NUL spec.

@didactic-drunk
Copy link
Author

New benchmark results:

  • encode short 4.20M (238.16ns) (±18.68%) 176B/op fastest
  • encode long 80.06k ( 12.49µs) (±13.37%) 6.11kB/op 52.45× slower

Old benchmark results:

  • encode short 3.32M (301.47ns) (± 3.11%) 272B/op fastest
  • encode long 44.99k ( 22.23µs) (± 2.54%) 15.7kB/op 73.73× slower

Code:

require "benchmark"
require "./src/base32"

bytes1 = "foobarbaz".to_slice
bytes2 = Bytes.new 1024
Benchmark.ips do |bm|
  bm.report "encode short" do
    Base32.encode bytes1, false
  end

  bm.report "encode long" do
    Base32.encode bytes2, false
  end
end

New faster implementation of Base32.encode.
Correctly handle NUL bytes.
Add NUL spec.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants