Golang : Get number of CPU cores

Problem :

You want to find the maximum number of CPU cores to maximize performance.

Solution :

Use the runtime package to find out the number of CPU cores available on local machine.

 package main

 import (

 func main() {

 cores := runtime.NumCPU()

 fmt.Printf("This machine has %d CPU cores. \n", cores)

 // maximize CPU usage for maximum performance


Reference :


By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.