Skip to content

Commit

Permalink
v0.0.7 - 修复多核测试时,若仅单核存在不进行多核测试
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jul 1, 2024
1 parent dec5fd9 commit f6d80d6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
TAG="v0.0.6-$(date +'%Y%m%d%H%M%S')"
TAG="v0.0.7-$(date +'%Y%m%d%H%M%S')"
git tag $TAG
git push origin $TAG
env:
Expand Down
68 changes: 35 additions & 33 deletions cpu/cputest.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,45 +99,47 @@ func SysBenchTest(language, testThread string) string {
result += "1 线程测试(单核)得分: "
}
result += singleScore + "\n"
multiResult, err := runSysBenchCommand(fmt.Sprintf("%d", runtime.NumCPU()), "5", version)
if err == nil {
tempList := strings.Split(multiResult, "\n")
for _, line := range tempList {
if strings.Contains(line, "events per second:") {
temp1 := strings.Split(line, ":")
if len(temp1) == 2 {
multiScore = temp1[1]
}
} else if multiScore == "" && totalTime == "" && strings.Contains(line, "total time:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
totalTime = strings.ReplaceAll(temp[1], "s", "")
}
} else if multiScore == "" && totalEvents == "" && strings.Contains(line, "total number of events:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
totalEvents = temp[1]
if runtime.NumCPU() > 1 {
multiResult, err := runSysBenchCommand(fmt.Sprintf("%d", runtime.NumCPU()), "5", version)
if err == nil {
tempList := strings.Split(multiResult, "\n")
for _, line := range tempList {
if strings.Contains(line, "events per second:") {
temp1 := strings.Split(line, ":")
if len(temp1) == 2 {
multiScore = temp1[1]
}
} else if multiScore == "" && totalTime == "" && strings.Contains(line, "total time:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
totalTime = strings.ReplaceAll(temp[1], "s", "")
}
} else if multiScore == "" && totalEvents == "" && strings.Contains(line, "total number of events:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
totalEvents = temp[1]
}
}
}
}
if multiScore == "" && totalTime != "" && totalEvents != "" {
totalEventsFloat, err1 := strconv.ParseFloat(totalEvents, 64)
if err1 == nil {
totalTimeFloat, err2 := strconv.ParseFloat(totalTime, 64)
if err2 == nil {
multiScoreFloat := totalEventsFloat / totalTimeFloat
multiScore = strconv.FormatFloat(multiScoreFloat, 'f', 2, 64)
totalTime, totalEvents = "", ""
if multiScore == "" && totalTime != "" && totalEvents != "" {
totalEventsFloat, err1 := strconv.ParseFloat(totalEvents, 64)
if err1 == nil {
totalTimeFloat, err2 := strconv.ParseFloat(totalTime, 64)
if err2 == nil {
multiScoreFloat := totalEventsFloat / totalTimeFloat
multiScore = strconv.FormatFloat(multiScoreFloat, 'f', 2, 64)
totalTime, totalEvents = "", ""
}
}
}
}
if language == "en" {
result += fmt.Sprintf("%d", runtime.NumCPU()) + " Thread(s) Test: "
} else {
result += fmt.Sprintf("%d", runtime.NumCPU()) + " 线程测试(多核)得分: "
}
result += multiScore + "\n"
}
if language == "en" {
result += fmt.Sprintf("%d", runtime.NumCPU()) + " Thread(s) Test: "
} else {
result += fmt.Sprintf("%d", runtime.NumCPU()) + " 线程测试(多核)得分: "
}
result += multiScore + "\n"
}
}
return result
Expand Down
2 changes: 1 addition & 1 deletion cpu/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package cpu

const CpuTestVersion = "v0.0.6"
const CpuTestVersion = "v0.0.7"

0 comments on commit f6d80d6

Please sign in to comment.