How to find out the number of CPUs in Go lang?

Kirill Fuchs picture Kirill Fuchs · Jun 6, 2014 · Viewed 17.8k times · Source

Is there a simple way to find out the number of CPU's on a local machine using Go lang?

Answer

Eve Freeman picture Eve Freeman · Jun 6, 2014

http://play.golang.org/p/cuaf2ZHLIx

package main

import (  
    "fmt"
    "runtime"
)

func main() {
    fmt.Println(runtime.NumCPU())
}