Skip to content

Instantly share code, notes, and snippets.

@quux00
Created July 2, 2015 01:30
Show Gist options
  • Save quux00/b16238a795878248e06b to your computer and use it in GitHub Desktop.
Save quux00/b16238a795878248e06b to your computer and use it in GitHub Desktop.
list-binary.Read.pprof
(pprof) list binary.Read
Total: 4.27mins
5.02s 25.50s (flat, cum) 9.96% of Total
. . 137:// When reading into a struct, all non-blank fields must be exported.
330ms 330ms 138:func Read(r io.Reader, order ByteOrder, data interface{}) error {
. . 139: // Fast path for basic types and slices.
430ms 2.85s 140: if n := intDataSize(data); n != 0 {
240ms 6.85s 141: var b [8]byte
130ms 130ms 142: var bs []byte
20ms 20ms 143: if n > len(b) {
. . 144: bs = make([]byte, n)
. . 145: } else {
140ms 140ms 146: bs = b[:n]
. . 147: }
1s 7.33s 148: if _, err := io.ReadFull(r, bs); err != nil {
. . 149: return err
. . 150: }
2.01s 4.49s 151: switch data := data.(type) {
. . 152: case *int8:
. . 153: *data = int8(b[0])
. . 154: case *uint8:
. . 155: *data = b[0]
. . 156: case *int16:
. . 157: *data = int16(order.Uint16(bs))
. . 158: case *uint16:
. . 159: *data = order.Uint16(bs)
. . 160: case *int32:
. . 161: *data = int32(order.Uint32(bs))
. . 162: case *uint32:
. . 163: *data = order.Uint32(bs)
. . 164: case *int64:
. . 165: *data = int64(order.Uint64(bs))
. . 166: case *uint64:
510ms 3.15s 167: *data = order.Uint64(bs)
. . 168: case []int8:
. . 169: for i, x := range bs { // Easier to loop over the input for 8-bit values.
. . 170: data[i] = int8(x)
. . 171: }
. . 172: case []uint8:
. . 173: copy(data, bs)
. . 174: case []int16:
. . 175: for i := range data {
. . 176: data[i] = int16(order.Uint16(bs[2*i:]))
. . 177: }
. . 178: case []uint16:
. . 179: for i := range data {
. . 180: data[i] = order.Uint16(bs[2*i:])
. . 181: }
. . 182: case []int32:
. . 183: for i := range data {
. . 184: data[i] = int32(order.Uint32(bs[4*i:]))
. . 185: }
. . 186: case []uint32:
. . 187: for i := range data {
. . 188: data[i] = order.Uint32(bs[4*i:])
. . 189: }
. . 190: case []int64:
. . 191: for i := range data {
. . 192: data[i] = int64(order.Uint64(bs[8*i:]))
. . 193: }
. . 194: case []uint64:
. . 195: for i := range data {
. . 196: data[i] = order.Uint64(bs[8*i:])
. . 197: }
. . 198: }
210ms 210ms 199: return nil
. . 200: }
. . 201:
. . 202: // Fallback to reflect-based decoding. (rest ommitted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment