package main import ( "errors" "fmt" "strings" "time" ) type BenchmarkConfig struct { DurationSecs int `json:"durationSecs"` Intensity int `json:"intensity"` CoreFilter int `json:"coreFilter"` MultiCore bool `json:"multiCore"` } type CPUInfo struct { BrandString string `json:"brandString"` VendorID string `json:"vendorID"` PhysicalCores int `json:"physicalCores"` LogicalCores int `json:"logicalCores"` BaseClockMHz int `json:"baseClockMHz"` BoostClockMHz int `json:"boostClockMHz"` L1DataKB int `json:"l1DataKB"` L2KB int `json:"l2KB"` L3MB int `json:"l3MB"` IsHybrid bool `json:"isHybrid,omitempty"` Has3DVCache bool `json:"has3DVCache,omitempty"` PCoreCount int `json:"pCoreCount,omitempty"` ECoreCount int `json:"eCoreCount,omitempty"` Cores []CPUCoreDescriptor `json:"cores,omitempty"` SupportedFeatures []string `json:"supportedFeatures,omitempty"` } type CPUCoreDescriptor struct { LogicalID int `json:"LogicalID"` PhysicalID int `json:"PhysicalID"` CoreID int `json:"CoreID"` Type int `json:"Type"` } type CoreResult struct { LogicalID int `json:"logicalID"` CoreType string `json:"coreType"` MOpsPerSec float64 `json:"mOpsPerSec"` TotalOps int64 `json:"totalOps"` } type BenchmarkResult struct { Config BenchmarkConfig `json:"config"` CPUInfo CPUInfo `json:"cpuInfo"` StartedAt time.Time `json:"startedAt"` Duration int64 `json:"duration"` TotalOps int64 `json:"totalOps"` MOpsPerSec float64 `json:"mOpsPerSec"` Score int64 `json:"score"` CoreResults []CoreResult `json:"coreResults"` } type Submission struct { SubmissionID string `json:"submissionID"` Submitter string `json:"submitter"` SubmittedAt time.Time `json:"submittedAt"` BenchmarkResult } func (b BenchmarkResult) Validate() error { if strings.TrimSpace(b.CPUInfo.BrandString) == "" { return errors.New("cpuInfo.brandString is required") } if b.StartedAt.IsZero() { return errors.New("startedAt is required and must be RFC3339-compatible") } if b.Config.DurationSecs <= 0 { return errors.New("config.durationSecs must be greater than zero") } if b.Duration <= 0 { return errors.New("duration must be greater than zero") } if b.TotalOps < 0 || b.Score < 0 || b.MOpsPerSec < 0 { return errors.New("duration, totalOps, mOpsPerSec, and score must be non-negative") } if b.CPUInfo.LogicalCores < 0 || b.CPUInfo.PhysicalCores < 0 { return errors.New("cpu core counts must be non-negative") } for _, result := range b.CoreResults { if result.LogicalID < 0 { return fmt.Errorf("coreResults.logicalID must be non-negative") } if result.MOpsPerSec < 0 || result.TotalOps < 0 { return fmt.Errorf("coreResults values must be non-negative") } } return nil } func normalizeSubmitter(submitter string) string { submitter = strings.TrimSpace(submitter) if submitter == "" { return "Anonymous" } return submitter } func threadModeLabel(multiCore bool) string { if multiCore { return "Multi-threaded" } return "Single-threaded" }