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
+26.1k Golang : How to read integer value from standard input ?
+8.1k Golang : Grayscale Image
+18.7k Golang : Generate thumbnails from images
+13.8k Golang : Get user input until a command or receive a word to stop
+9.3k Golang : does not implement flag.Value (missing Set method)
+6.1k Javascript : Get operating system and browser information
+7.8k Gogland : Where to put source code files in package directory for rookie
+21k Golang : Underscore or snake_case to camel case example
+11.8k Android Studio : Create custom icons for your application example
+6.3k Golang : Process non-XML/JSON formatted ASCII text file example
+6.3k PHP : Get client IP address
+7.6k Golang : Check to see if *File is a file or directory