Documentation ¶
Overview ¶
Package parhash presents tools for making it easy to generate multiple hash sums over the same data. It does this in parallel, spreading the computation work over all available CPUs.
Parhash has a speed advantage over serial operations when working with multiple hash algorithms over large data. Run the benchmark to see the difference over serial operation on your machine:
go test -bench .
On my machine, i7 3.5Ghz dual core I get a speed up of about 240%
BenchmarkSerial-4 500 3577258 ns/op BenchmarkParallel-4 1000 1458583 ns/op
For smaller data sets parhash won't see significant performance advantages due to the overhead of using channels and goroutines distribute the work.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Parhash ¶
Parhash distributes hash sum computation over all CPU cores. It is an io.Writer so it works well with data handling tools in the Go standard library
Example (Usage) ¶
p := New() // Add returns the same hash to make creation and assignment more concise hash1 := p.Add(md5.New()) hash2 := p.Add(sha1.New()) // Parhash is an io.Writer fmt.Fprintf(p, "Hello World") fmt.Printf("MD5 : %s\n", hex.EncodeToString(hash1.Sum(nil))) fmt.Printf("SHA1: %s", hex.EncodeToString(hash2.Sum(nil)))
Output: MD5 : b10a8db164e0754105b7a99be72e3fe5 SHA1: 0a4d55a8d778e5022fab701977c5d840bbc486d0