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
+13.7k Golang : unknown escape sequence error
+4k Detect if Google Analytics and Developer Media are loaded properly or not
+10.5k Golang : Select region of interest with mouse click and crop from image
+23.1k Golang : Print out struct values in string format
+15.9k Golang : Get file permission
+16k Golang : How to check if input from os.Args is integer?
+9.3k Golang : Create unique title slugs example
+12.7k Swift : Convert (cast) Int or int32 value to CGFloat
+5.7k Javascript : How to replace HTML inside <div>?
+30.8k Golang : Interpolating or substituting variables in string examples
+8.4k Golang : How to check if input string is a word?
+14.4k Golang : How to filter a map's elements for faster lookup