Go is well suited to data processing and computation because it compiles to fast native code, has built-in concurrency, and ships a standard library for the usual formats and algorithms. For most jobs you combine four things: streaming input with bufio and encoding/*, generic helpers from slices and maps, iterators (Go 1.23+), and goroutines for parallel work.
This guide shows those techniques with complete examples you can adapt to ETL scripts, log analysis, batch jobs, and numeric work.
Read large files record by record so memory use stays flat. bufio.Scanner handles lines, and encoding/csv handles CSV with proper quoting.
For JSON, use json.NewDecoder(r) and call Decode in a loop to read newline-delimited JSON, instead of json.Unmarshal on a whole file. Note that bufio.Scanner limits a line to 64 KiB by default; call scanner.Buffer to raise it for long lines.
Since Go 1.21 the slices and maps packages provide generic sort, search, and compare helpers, and generics let you write reusable map, filter, and reduce functions with type safety.
Pre-allocate with make([]T, 0, n) when you know the size, since repeated growth is a common source of avoidable allocation.
Go 1.23 added range-over-func and the iter package. An iter.Seq[T] produces values on demand, so you can chain steps without building intermediate slices. slices.Values, slices.Collect, maps.Keys, and slices.Sorted connect iterators to collections.
CPU-bound work scales across cores with goroutines. A fixed pool of workers reading from a channel keeps concurrency bounded.
The producer closes jobs, a separate goroutine closes results once all workers finish, and the main goroutine drains results. For error handling and cancellation, use errgroup from golang.org/x/sync with a context.
| Need | Tool |
|---|---|
| Basic math, trig, rounding | math |
| Integers beyond 64 bits | math/big (big.Int) |
| Exact decimals and money | integer cents, or a decimal library |
| Random numbers | math/rand/v2, and crypto/rand for security |
| Statistics, matrices | community packages such as Gonum |
Never use float64 for currency; store integer minor units. Floating-point results can differ in the last digits, so compare with a tolerance.
Write a benchmark and profile before tuning. Go includes both.
Run go test -bench=. -benchmem for time and allocations, and use pprof (go test -cpuprofile cpu.out) to find hot spots. b.Loop() is available from Go 1.24; on older versions use for i := 0; i < b.N; i++. Run go test -race on concurrent code.
Go is faster and uses less memory for pipelines, services, and batch jobs, and deploys as one binary. Python still has a richer ecosystem for exploratory analysis and machine learning.
For CPU-bound work, about runtime.NumCPU() workers. For I/O-bound work you can use more, but bound them with a pool or semaphore.
Stream it with bufio or a decoder, aggregate as you go, and keep only the results in memory.
Not required. Small generic helpers like the ones above, plus slices and maps, cover most needs.
Stream inputs, use generic helpers and iterators for transformations, parallelise CPU-bound work with a bounded worker pool, use math/big or integer units where precision matters, and let benchmarks and pprof guide optimisation.