2026-04-15 19:20:27 +03:00
|
|
|
package model
|
2026-04-15 19:09:21 +03:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:20:27 +03:00
|
|
|
func NormalizeSubmitter(submitter string) string {
|
2026-04-15 19:09:21 +03:00
|
|
|
submitter = strings.TrimSpace(submitter)
|
|
|
|
|
if submitter == "" {
|
|
|
|
|
return "Anonymous"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return submitter
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:20:27 +03:00
|
|
|
func ThreadModeLabel(multiCore bool) string {
|
2026-04-15 19:09:21 +03:00
|
|
|
if multiCore {
|
|
|
|
|
return "Multi-threaded"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "Single-threaded"
|
|
|
|
|
}
|
2026-04-15 19:20:27 +03:00
|
|
|
|
|
|
|
|
func CloneSubmission(submission *Submission) *Submission {
|
|
|
|
|
if submission == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
copySubmission := *submission
|
|
|
|
|
if len(submission.CoreResults) > 0 {
|
|
|
|
|
copySubmission.CoreResults = append([]CoreResult(nil), submission.CoreResults...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(submission.CPUInfo.Cores) > 0 {
|
|
|
|
|
copySubmission.CPUInfo.Cores = append([]CPUCoreDescriptor(nil), submission.CPUInfo.Cores...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(submission.CPUInfo.SupportedFeatures) > 0 {
|
|
|
|
|
copySubmission.CPUInfo.SupportedFeatures = append([]string(nil), submission.CPUInfo.SupportedFeatures...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ©Submission
|
|
|
|
|
}
|