• Type:

CH Show HN: Crunch – a fast buffer manipulation library in go

a library for easily manipulating bits and bytes in golang


license


godoc


travis


codecov


go report card


try it on repl.it

features | installation | benchmarks | examples

features

  • feature-rich: supports reading and writing integers of varying sizes in both little and big endian
  • performant: performs more than twice as fast as the standard library’s bytes.Buffer
  • simple and familiar: has a consistent and easy-to-use api
  • licensed under the mpl-2.0: use it anywhere you wish, just don’t change it privately

installation

install with the go tool

$ go get github.com/superwhiskers/crunch/v3

then, just import it in your project like this. easy!

package "yourpackage"

import crunch "github.com/superwhiskers/crunch/v3"

install using git submodules (not recommended)

# this assumes that you are in a git repository
$ git submodule add https://github.com/superwhiskers/crunch path/to/where/you/want/crunch

then, you can import it like this

package "yourpackage"

import crunch "github.com/your-username/project/path/to/crunch/v3"

benchmarks

both Buffer and MiniBuffer perform on average more than twice as fast as bytes.Buffer in both writing and reading

BenchmarkBufferWriteBytes-4             2000000000               1.45 ns/op            0 B/op          0 allocs/op
BenchmarkBufferReadBytes-4              2000000000               0.84 ns/op            0 B/op          0 allocs/op
BenchmarkBufferWriteU32LE-4             200000000                9.28 ns/op            0 B/op          0 allocs/op
BenchmarkBufferReadU32LE-4              50000000                26.6 ns/op             8 B/op          1 allocs/op
BenchmarkBufferReadBit-4                2000000000               0.84 ns/op            0 B/op          0 allocs/op
BenchmarkBufferReadBits-4               1000000000               2.25 ns/op            0 B/op          0 allocs/op
BenchmarkBufferSetBit-4                 1000000000               2.07 ns/op            0 B/op          0 allocs/op
BenchmarkBufferClearBit-4               1000000000               2.05 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferWriteBytes-4         2000000000               1.42 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferReadBytes-4          2000000000               0.58 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferWriteU32LE-4         200000000                8.79 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferReadU32LE-4          500000000                3.91 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferReadBit-4            2000000000               0.64 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferReadBits-4           300000000                5.64 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferSetBit-4             1000000000               2.03 ns/op            0 B/op          0 allocs/op
BenchmarkMiniBufferClearBit-4           1000000000               2.10 ns/op            0 B/op          0 allocs/op
BenchmarkStdByteBufferWrite-4           200000000                9.42 ns/op            0 B/op          0 allocs/op
BenchmarkStdByteBufferRead-4            500000000                3.36 ns/op            0 B/op          0 allocs/op

examples

examples can be found in the examples directory

acknowledgements

icon (cookie logo) made by freepik from flaticon.com

Read More

Previous Post

CH Show HN: Pruun – Python CL utility for creating AWS Lambda deployment packages

Next Post

CH Show HN: Introspect – Python OODB Web CMS built on UNIX

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top