Thursday, May 12, 2016

Getting CPU info with D (the D language)

By Vasudev Ram

I have been using the D programming language for some time.

From the D home page:

[ D is a systems programming language with C-like syntax and static typing. It combines efficiency, control and modeling power with safety and programmer productivity. ]

[ Some information about D:

- D Language home page
- D Overview
- D on Wikipedia ]

Here is a D program, cpu_info.d, that gets some information about the CPU of your machine.
// cpu_info.d
// Author: Vasudev Ram - 
import std.stdio;
import core.cpuid;
void main()
    writeln("processor: ", processor());
    writeln("vendor: ", vendor());
    writeln("hyperThreading: ", hyperThreading());
    writeln("threadsPerCPU: ", threadsPerCPU());
    writeln("coresPerCPU: ", coresPerCPU());
The program can be compiled and run with:
$ dmd cpu_info.d
dmd is the D compiler (the name stands for Digital Mars D). It creates cpu_info.exe which I can then run:
$ cpu_info
processor: Intel(R) Core(TM) i3-2328M CPU @ 2.20GHz
vendor: GenuineIntel
hyperThreading: true
threadsPerCPU: 4
coresPerCPU: 2
- Vasudev Ram - Online Python training and consulting

Signup to hear about my new courses and products.

My Python posts     Subscribe to my blog by email

My ActiveState recipes


Vasudev Ram said...

I had accidentally left out the source code from the post. It is included now.

Vasudev Ram said...

Put the code on Github, here:

cpu_info on Github