Open Carterpersall opened 1 year ago
You may get physical cores and logical cores ( threads ) at the same time with GetLogicalProcessorInformationEx(RelationAll)
Because this method requires copying more data from the kernel, I'm not sure whether it's faster than your implementation. Just another idea.
I added several alternative implementations
Implementation Speeds:
hyperfine --warmup 20 --prepare "cmd" --min-runs 200 ".\macchina.exe --show processor"
Plugged in:
GetLogicalProcessorInformation
GetNativeSystemInfo
GetLogicalProcessorInformation
)
On Battery life:
GetLogicalProcessorInformation
GetNativeSystemInfo
GetLogicalProcessorInformation
)
When heavily throttled (used power plans to downclock CPU to 1.06 GHz to simulate a slow computer)
GetLogicalProcessorInformation
GetNativeSystemInfo
GetLogicalProcessorInformation
)
There's virtually no difference between some of the implementations and those of num_cpus
, why not call those two functions directly?
According to stackoverflow, WMI, registry and GetLogicalProcessorInformationEx are only reliable ways to get the number of cpu logical cores (threads)
According to stackoverflow, WMI, registry and GetLogicalProcessorInformationEx are only reliable ways to get the number of cpu logical cores (threads)
That does seem to be the case. I've made a commit that addresses it. cpu_cores
now uses GetLogicalProcessorInformationEx
to get the number of cores, and has Registry and WMI based implementations as backups. cpu_physical_cores
now uses GetLogicalProcessorInformationEx
as well.
I used the implementation here as the basis of my implementation of GetLogicalProcessorInformationEx
.
Hi, I'm making a tool that can benefit from this. Any way we can get this merged?
I've got a Windows VM lying around but I'm a bit busy at the moment. If this works correctly, I don't have a problem accepting the PR. I would appreciate @uttarayan21's input on the state of this PR because he's much more knowledgeable on Windows than I am.
Hello, I'm a contributor to https://github.com/lptstr/winfetch (you've talked to the maintainer in #112), and would like to start applying some of the experience I gained there to this project.
cpu_physical_cores
GetLogicalProcessorInformation
and uses the returned buffer to get the computer's number of CPU corescpu_cores
HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor
and counts the number of subkeys