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
+20.3k Golang : Secure(TLS) connection between server and client
+5.8k Golang : Grab news article text and use NLP to get each paragraph's sentences
+10k Golang : How to check if a website is served via HTTPS
+13.8k Golang : Fix image: unknown format error
+6.6k Fix sudo yum hang problem with no output or error messages
+5.7k Golang : Shuffle array of list
+6.2k Golang : Handling image beyond OpenCV video capture boundary
+11.8k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+11.9k Golang : convert(cast) string to integer value
+42.8k Golang : Get hardware information such as disk, memory and CPU usage
+6.5k Golang : Humanize and Titleize functions
+8.6k Golang : Take screen shot of browser with JQuery example