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
+4.4k Swift : Convert (cast) Float to Int or Int32 value
+5.3k Golang : Convert Chinese UTF8 characters to Pin Yin
+15.7k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+6.2k Golang : Fibonacci number generator examples
+25.8k Golang : How to check if a connection to database is still alive ?
+13.7k Golang : Submit web forms without browser by http.PostForm example
+10.2k Golang : Read until certain character to break for loop
+10.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+10.7k Golang : Surveillance with web camera and OpenCV
+5k Fix fatal error: evacuation not done in time problem
+10.4k Golang : Concatenate (combine) buffer data example
+30.3k Golang : Convert an image file to []byte