Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 605
Kirill Fuchs Avatar asked Jun 06 '14 03:06

Kirill Fuchs


People also ask

How do I check how many CPUs I have?

Press Ctrl + Shift + Esc to open Task Manager. Select the Performance tab to see how many cores and logical processors your PC has.

Does go use multiple cores?

Go has an M:N scheduler that can also utilize multiple processors. At any time, M goroutines need to be scheduled on N OS threads that run on at most on GOMAXPROCS numbers of processors. At any time, at most only one thread is allowed to run per core.

How do I find the CPU number in Python?

cpu_count() method in Python is used to get the number of CPUs in the system. This method returns None if number of CPUs in the system is undetermined. Parameter: No parameter is required. Return Type: This method returns an integer value which denotes the number of CPUs in the system.


1 Answers

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

package main  import (       "fmt"     "runtime" )  func main() {     fmt.Println(runtime.NumCPU()) } 
like image 200
Eve Freeman Avatar answered Sep 21 '22 15:09

Eve Freeman