Menu Close

Go – How to find out the number of CPUs in Go

In this tutorial, We are going to learn about How to find out the number of CPUs in Go. We can do it by using NumCPU() function in runtime package in go.

NumCPU() function is also used to find out the number of logical CPUs usable by the current process.

Function Prototype:

func NumCPU() int

Return type:

NumCPU() function of runtime package returns 
the number of logical CPUs usable by the 
current process.

Example with code:

package main

import (

  "fmt"
  "runtime"

)

func main() {

  fmt.Println(runtime.NumCPU())
}

Output:

8

To learn more about golang, You can refer given below link:

https://techieindoor.com/go-lang-tutorial/

References:

 https://golang.org/doc/
https://golang.org/pkg/
https://golang.org/pkg/fmt/
https://golang.org/pkg/fmt/#Println
Posted in golang, runtime

Leave a Reply

Your email address will not be published. Required fields are marked *