Here is a simple D language utility, num_cores.d, which, when compiled (once) and run (any number of times), will show you the number of cores in the processor in your PC:
// num_cores.d // A utility to show the number of cores in the processor in your PC. import std.stdio; import std.parallelism; int num_cores() { return totalCPUs; } void main() { writeln("This computer's processor has ", num_cores, " core(s)."); }The program uses the function totalCPUs from the D standard library module std.parallelism to get the number of cores.
To use it, download and install a D compiler such as DMD, the Digital Mars D compiler (or LDC or GDC). Use of DMD is shown here.
Then compile the program with:
dmd num_cores.dThen run it:
num_coresOutput:
This computer's processor has 4 core(s).
- Vasudev Ram - Online Python training and consulting Get updates on my software products / ebooks / courses. Jump to posts: Python DLang xtopdf Subscribe to my blog by email My ActiveState recipes
No comments:
Post a Comment