Skip to content

Commit

Permalink
fix: adjusted CPU stress test to prevent compiler to optimize it (#2391)
Browse files Browse the repository at this point in the history
  • Loading branch information
exelban committed Feb 19, 2025
1 parent 8ac0b52 commit fa7b3bb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Kit/helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ public class CPUeStressTest {

let efficientCoreCount = ProcessInfo.processInfo.processorCount / 2
self.workers.removeAll()

for index in 0..<efficientCoreCount {
let worker = DispatchWorkItem { [weak self] in
self?.test(threadIndex: index)
Expand All @@ -1664,8 +1664,9 @@ public class CPUeStressTest {

private func test(threadIndex: Int) {
pthread_set_qos_class_self_np(QOS_CLASS_BACKGROUND, 0)
var result: Double = 0.0
while isRunning {
_ = sqrt(987654.321)
result += sqrt(987654.321)
}
}
}
Expand Down Expand Up @@ -1702,8 +1703,9 @@ public class CPUpStressTest {

private func test(threadIndex: Int) {
pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0)
var result: Double = 0.0
while isRunning {
_ = sqrt(987654.321)
result += sqrt(987654.321)
}
}
}
Expand Down

0 comments on commit fa7b3bb

Please sign in to comment.