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
+14.1k Golang : Compress and decompress file with compress/flate example
+5.3k JavaScript/JQuery : Redirect page examples
+7.5k Golang : Check to see if *File is a file or directory
+31k Golang : Interpolating or substituting variables in string examples
+4.9k Javascript : How to get width and height of a div?
+4.9k HTTP common errors and their meaning explained
+9.3k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+7.7k Golang : Convert(cast) io.Reader type to string
+10k Golang : Get escape characters \u form from unicode characters
+6.4k Golang : Test input string for unicode example
+12.4k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+13.8k Golang : Qt progress dialog example