Skip to content

Instantly share code, notes, and snippets.

@quux00
Created July 2, 2015 01:40
Show Gist options
  • Save quux00/a9c746a7bb9a54f5a052 to your computer and use it in GitHub Desktop.
Save quux00/a9c746a7bb9a54f5a052 to your computer and use it in GitHub Desktop.
(pprof) list varint.VarintEncode
5.89s 26.37s (flat, cum) 39.97% of Total
. . 40://
190ms 190ms 41:func VarintEncode(w io.Writer, v uint64) error {
230ms 4.35s 42: ba := [1]byte{}
410ms 410ms 43: nexp := 0
. . 44: ntot := 0
210ms 210ms 45: for (v & 0xFFFFFFFFFFFFFF80) != 0 {
280ms 280ms 46: ba[0] = byte((v & 0x7F) | 0x80)
-> 2.51s 15.19s 47: n, _ := w.Write(ba[:])
420ms 420ms 48: ntot += n
360ms 360ms 49: nexp++
260ms 260ms 50: v >>= 7
. . 51: }
90ms 90ms 52: ba[0] = byte(v & 0x7F)
570ms 4.25s 53: n, err := w.Write(ba[:])
50ms 50ms 54: ntot += n
40ms 40ms 55: nexp++
80ms 80ms 56: if err != nil {
. . 57: return oerror.NewTrace(err)
. . 58: }
. . 59: if ntot != nexp {
. . 60: return fmt.Errorf("Incorrect number of bytes written." +
. . 61: " Expected %d. Actual %d", nexp, ntot)
. . 62: }
190ms 190ms 63: return nil
. . 64:}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment