DEV Community

Jodhi
Jodhi

Posted on • Edited on

BLAKE3 Go Libraries simple comparison

Official Go Library for BLAKE3 is not available at the time of this post.

But, we have two alternative:
github.com/lukechampine/blake3
A pure Go implementation of the BLAKE3 cryptographic hash function

github.com/zeebo/blake3
Pure Go implementation of BLAKE3 with AVX2 and SSE4.1 acceleration

CPU used: intel i7-8550U

Simple benchmark code

package main

import (
    "bytes"
    "encoding/hex"
    "fmt"
    "testing"

    zeeboBLAKE3 "github.com/zeebo/blake3"
    lukechampineBLAKE3 "lukechampine.com/blake3"
)

var longBytes = bytes.Repeat([]byte("A"), 1000000)

func benchmarkLukechampine(b *testing.B) {
    for i := 0; i < b.N; i++ {
        hasher := lukechampineBLAKE3.New(32, nil)
        hasher.Write([]byte(longBytes))
        hex.EncodeToString(hasher.Sum(nil))
    }
}
func benchmarkZeebo(b *testing.B) {
    for i := 0; i < b.N; i++ {
        hasher := zeeboBLAKE3.New()
        hasher.Write([]byte(longBytes))
        hex.EncodeToString(hasher.Sum(nil))
    }
}

func main() {
    fmt.Println("lukechampine 1st test:", testing.Benchmark(benchmarkLukechampine))
    fmt.Println("zeebo 1st test:", testing.Benchmark(benchmarkZeebo))
    fmt.Println("lukechampine 2nd test:", testing.Benchmark(benchmarkLukechampine))
    fmt.Println("zeebo 2nd test:", testing.Benchmark(benchmarkZeebo))
}

The result

lukechampine 1st test:      577    2171834 ns/op
zeebo 1st test:     4146        302500 ns/op
lukechampine 2nd test:      532    2282167 ns/op
zeebo 2nd test:     3448        331177 ns/op

Performance wise, the zeebo lib is faster. This benchmark is still limited since other resources not taken into consideration. If you guys want to try BLAKE3 hasher online or generate fancy text. Thank you.

Top comments (0)