FAQ
i use encoding/binary package for testing the binary write/read speed, but
it reach 12MB/s at most.
What is the fastest way to read/write binary file using go?

source code:

type Action struct {
U1 uint64
U2 uint64
U3 uint64
}

f, _ := os.Create("test.dat")
defer f.Close()

w := bufio.NewWriter(f)
var action Action
for {
binary.Write(w, binary.LittleEndian, &action)
}

--

Search Discussions

  • Roger peppe at Nov 7, 2012 at 2:58 pm
    binary.Write is not fast. if you need speed, use the
    binary.LittleEndian methods directly, writing to
    a buffer that's allocated only once.

    sometimes i wonder about a tool that can generate code
    for drop-in replacements for binary.Write and binary.Read
    containing special case code for chosen data structures.

    it would not be hard.
    On 7 November 2012 08:13, go-sky wrote:
    type Action struct {
    U1 uint64
    U2 uint64
    U3 uint64
    }

    f, _ := os.Create("test.dat")
    defer f.Close()

    w := bufio.NewWriter(f)
    var action Action
    for {
    binary.Write(w, binary.LittleEndian, &action)
    }
    --
  • Minux at Nov 7, 2012 at 3:10 pm

    On Wed, Nov 7, 2012 at 10:58 PM, roger peppe wrote:

    binary.Write is not fast. if you need speed, use the
    binary.LittleEndian methods directly, writing to
    a buffer that's allocated only once.

    sometimes i wonder about a tool that can generate code
    for drop-in replacements for binary.Write and binary.Read
    containing special case code for chosen data structures.

    it would not be hard.
    There is one such project:
    http://code.google.com/p/gobin-codegen/

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 7, '12 at 1:52p
activeNov 7, '12 at 3:10p
posts3
users3
websitegolang.org

3 users in discussion

Minux: 1 post Go-sky: 1 post Roger peppe: 1 post

People

Translate

site design / logo © 2021 Grokbase