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 (
"fmt"
"runtime"
)
func main() {
cores := runtime.NumCPU()
fmt.Printf("This machine has %d CPU cores. \n", cores)
// maximize CPU usage for maximum performance
runtime.GOMAXPROCS(cores)
}
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.
Advertisement
Tutorials
+5.8k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+10.2k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+7.3k Golang : Shuffle strings array
+6.7k Golang : Fibonacci number generator examples
+8.8k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+9.7k Golang : Translate language with language package example
+7.2k Android Studio : AlertDialog to get user attention example
+8.5k Golang : Heap sort example
+7k Golang : File system scanning
+14.1k Golang : On enumeration
+12.2k Golang : Exit, terminating or aborting a program