Files
mtusi2026lab4-fork/student-tests/kdf-bench.go.txt
T

24 lines
600 B
Plaintext

package main
import (
"encoding/json"
"os"
"runtime"
"runtime/debug"
"time"
"golang.org/x/crypto/argon2"
)
func main() {
samples:=[]float64{}
for i:=0;i<5;i++ {
start:=time.Now()
hash:=argon2.IDKey([]byte("synthetic-diagnostic-password"),[]byte("synthetic-salt12"),3,64*1024,1,32)
runtime.KeepAlive(hash)
samples=append(samples,float64(time.Since(start).Microseconds())/1000)
debug.FreeOSMemory()
}
stats,_:=os.ReadFile("/sys/fs/cgroup/cpu.stat")
json.NewEncoder(os.Stdout).Encode(map[string]any{"kdf_ms":samples,"cpu_stat":string(stats),"gomaxprocs":runtime.GOMAXPROCS(0)})
}