Skip to content

Commit 96d2dc5

Browse files
committed
cpu_count: apple: handle apple silicon and intel
1 parent f4936e0 commit 96d2dc5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

benchmark/cpu.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ unsigned int cpu_count(){
127127
int N;
128128
size_t size = sizeof(N);
129129

130-
if (sysctlbyname("hw.physicalcpu", &N, &size, nullptr, 0) == 0)
130+
if (sysctlbyname("hw.perflevel0.physicalcpu", &N, &size, nullptr, 0) == 0) {
131+
// Apple Silicon performance core count
131132
NumberOfPhysicalCPU = N;
133+
}
134+
else if (sysctlbyname("hw.physicalcpu", &N, &size, nullptr, 0) == 0) {
135+
// assumes heterogenous cores e.g. Intel Mac
136+
NumberOfPhysicalCPU = N;
137+
}
132138

133139
#elif defined(_SC_NPROCESSORS_ONLN)
134140

0 commit comments

Comments
 (0)