package
0.0.0-20240525155241-a2cb4a3be2b2
Repository: https://github.com/vardhanapoorv/play-atomic-increment-file.git
Documentation: pkg.go.dev

# README

String vs Binary Data

  • Save integer as string in file, steps involved -
    • Convert integer to string - Using itoa() function, which has an interesting optimization for two digit numbers - Commit, CodeRef.
    • Write string to file - Using WriteString function, which internals converts string to bytes. Then calls Write function to write bytes to file.
  • Save integer as binary encoded data in file, steps involved -
    • Convert integer to binary encoded data - Using binary.LittleEndian.PutUint64 function, which converts integer to bytes.
    • Write binary encoded data to file - Using Write function to write bytes to file.

The string path has a extra step of converting integer to string first then to bytes, whereas the binary path makes that conversion to bytes in binary encoded form much quicker.

Benchmark

String/binary "42"

String/binary "421"