package main import ( "crypto/rand" "encoding/base64" "fmt" "log" "net/http" "runtime" "github.com/google/uuid" "golang.org/x/crypto/argon2" ) func main() { // Ensure we use all available cores for maximum performance numCPU := runtime.NumCPU() runtime.GOMAXPROCS(numCPU) log.Printf("Server starting with %d CPU cores available", numCPU) // Setup routes http.HandleFunc("/", benchmarkHandler) // Start server log.Println("Benchmark API server listening on :5001") if err := http.ListenAndServe(":5001", nil); err != nil { log.Fatalf("Server failed to start: %v", err) } } func benchmarkHandler(w http.ResponseWriter, r *http.Request) { // Generate a new UUID for this request id := uuid.New() // Generate a random salt salt := make([]byte, 16) if _, err := rand.Read(salt); err != nil { http.Error(w, "Failed to generate salt", http.StatusInternalServerError) return } // Run expensive Argon2id hashing operation // Parameters chosen to be computationally expensive // - time: 3 iterations (higher values increase computation time) // - memory: 64 MB (higher values increase memory usage) // - threads: 4 (adjust based on testing, too high might cause contention) // - key length: 32 bytes hash := argon2.IDKey([]byte(id.String()), salt, 3, 64*1024, 4, 32) hashStr := base64.StdEncoding.EncodeToString(hash) // Return the result w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, `{"uuid":"%s","hash":"%s"}`, id, hashStr) }