config/bench_test.go

45 lines
695 B
Go
Raw Permalink Normal View History

package config
import (
"os"
"testing"
)
2026-05-02 13:36:06 +08:00
func BenchmarkLoad(b *testing.B) {
os.WriteFile("bench.json", []byte(`{"name":"bench-test","sets":[1,2,3]}`), 0644)
defer os.Remove("bench.json")
2026-05-02 13:36:06 +08:00
var conf struct {
Name string
Sets []int
}
2026-05-02 13:36:06 +08:00
b.ResetTimer()
for i := 0; i < b.N; i++ {
2026-05-02 13:36:06 +08:00
_ = Load("bench", &conf)
}
}
func BenchmarkApplyEnvOverrides(b *testing.B) {
os.Setenv("APP_DB_HOST", "localhost")
os.Setenv("APP_DB_PORT", "5432")
os.Setenv("APP_SERVER_TIMEOUT", "30s")
2026-05-02 13:36:06 +08:00
var conf struct {
App struct {
Db struct {
Host string
Port int
}
Server struct {
Timeout Duration
}
}
}
2026-05-02 13:36:06 +08:00
b.ResetTimer()
for i := 0; i < b.N; i++ {
applyEnvOverrides(&conf)
}
}