Documentation
¶
Index ¶
- func ConcurrentSum1(fileName string) (ret int64, _ error)
- func ConcurrentSum2(fileName string, workers int) (ret int64, _ error)
- func ConcurrentSum3(fileName string, workers int) (ret int64, _ error)
- func ConcurrentSum4(fileName string, workers int) (ret int64, _ error)
- func ParseInt(input []byte) (n int64, _ error)
- func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error)
- func Sum(fileName string) (ret int64, _ error)
- func Sum2(fileName string) (ret int64, _ error)
- func Sum2_scanner(fileName string) (ret int64, err error)
- func Sum3(fileName string) (ret int64, _ error)
- func Sum4(fileName string) (ret int64, err error)
- func Sum4_atoi(fileName string) (ret int64, err error)
- func Sum5(fileName string) (ret int64, err error)
- func Sum5_line(fileName string) (ret int64, err error)
- func Sum6(fileName string) (ret int64, err error)
- func Sum6Reader(r io.Reader, buf []byte) (ret int64, err error)
- func Sum7(fileName string) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConcurrentSum1 ¶
ConcurrentSum1 performs sum concurrently. A lot slower than ConcurrentSum3. An example of pessimisation. Read more in "Efficient Go"; Example 10-10.
func ConcurrentSum2 ¶
ConcurrentSum2 performs sum concurrently. A lot slower than ConcurrentSum3. An example of pessimisation. Read more in "Efficient Go"; Example 10-11.
func ConcurrentSum3 ¶
ConcurrentSum3 uses coordination free sharding to perform more efficient computation. Read more in "Efficient Go"; Example 10-12.
func ConcurrentSum4 ¶
ConcurrentSum4 is like ConcurrentSum3, but it reads file in sharded way too. Read more in "Efficient Go"; Example 10-13.
func Sum ¶
Sum is a naive implementation and algorithm for summing integers from file. Read more in "Efficient Go"; Example 4-1.
func Sum2 ¶
Sum2 is sum with optimized the first latency + CPU bottleneck bytes.Split. bytes.Split look complex to hande different cases. It allocates a lot causing It looks like the algo is simple enough to just implement on our own (tried scanner := bufio.NewScanner(f) but it's slower). 30% less latency and 5x less memory than Sum. Read more in "Efficient Go"; Example 10-3.
func Sum2_scanner ¶
Sum2_scanner is a sum attempting using scanner. Actually slower than Sum2, but uses less memory.
func Sum3 ¶
Sum3 is a sum with optimized the second latency + CPU bottleneck: string conversion. On CPU profile we see byte to string conversion not only allocate memory, but also takes precious time. Let's perform zeroCopy conversion. 2x less latency memory than Sum2. Read more in "Efficient Go"; Example 10-4.
func Sum4 ¶
Sum4 is a sum with optimized the second latency + CPU bottleneck: ParseInt and string conversion. On CPU profile we see that ParseInt does a lot of checks that we might not need. We write our own parsing straight from byte to avoid conversion CPU time. 2x less latency, same mem as Sum3. Read more in "Efficient Go"; Example 10-5.
func Sum5 ¶
Sum5 is like Sum4, but noticing that it takes time to even allocate 21 MB on heap (and read file to it). Let's try to use scanner instead. Slower than Sum4 and Sum6 because scanner is not optimized for this...? Scanner takes 73% of CPU time. Read more in "Efficient Go"; Example 10-7.
Types ¶
This section is empty.