作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
num_cpus crate 给了我内核的数量,但这包括超线程内核。在我的例子中,这比使用真正的核心慢得多(几乎是 2 倍)。
最佳答案
您可以使用 rust binding 来做到这一点对于 hwloc此博客中描述的库 post .
它可以在各种平台下使用,并允许您像这样获取物理内核和逻辑处理单元的数量(在超线程的情况下)(来自博客文章的代码):
extern crate hwloc;
use hwloc::{Topology, ObjectType};
fn main() {
// Create a new Topology
let topology = Topology::new();
// Get all objects with type "Core"
let cores = topology.objects_with_type(&ObjectType::Core);
// Match on the returned Result and print the length if successful.
match cores {
Ok(c) => println!("There are {} cores on this machine.", c.len()),
Err(e) => panic!(format!("Could not load cores because of: {:?}", e))
}
}
关于rust - 我怎样才能得到真正的核心数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34205771/
我是一名优秀的程序员,十分优秀!