34 releases (19 stable)

1.13.0 Apr 15, 2020
1.12.0 Jan 16, 2020
1.11.1 Nov 12, 2019
1.10.1 Jun 10, 2019
0.1.0 Mar 16, 2015

#2 in Hardware support

Download history 195519/week @ 2020-03-16 202727/week @ 2020-03-23 200666/week @ 2020-03-30 200010/week @ 2020-04-06 218642/week @ 2020-04-13 232810/week @ 2020-04-20 230595/week @ 2020-04-27 227787/week @ 2020-05-04 249262/week @ 2020-05-11 241512/week @ 2020-05-18 239086/week @ 2020-05-25 252814/week @ 2020-06-01 257652/week @ 2020-06-08 244757/week @ 2020-06-15 251684/week @ 2020-06-22 233556/week @ 2020-06-29

865,679 downloads per month
Used in 7,288 crates (505 directly)


640 lines


crates.io Travis CI Status AppVeyor status

Count the number of CPUs on the current machine.


Add to Cargo.toml:

num_cpus = "1.0"

In your main.rs or lib.rs:

extern crate num_cpus;

// count logical cores this process could try to use
let num = num_cpus::get();


A crate with utilities to determine the number of CPUs available on the current system.

Sometimes the CPU will exaggerate the number of CPUs it contains, because it can use processor tricks to deliver increased performance when there are more threads. This crate provides methods to get both the logical and physical numbers of cores.

This information can be used as a guide to how many tasks can be run in parallel. There are many properties of the system architecture that will affect parallelism, for example memory access speeds (for all the caches and RAM) and the physical architecture of the processor, so the number of CPUs should be used as a rough guide only.


Fetch the number of logical CPUs.

let cpus = num_cpus::get();

See rayon::Threadpool for an example of where the number of CPUs could be used when setting up parallel jobs (Where the threadpool example uses a fixed number 8, it could use the number of CPUs).