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
+5.7k Golang : Convert Chinese UTF8 characters to Pin Yin
+8.2k Golang : Convert(cast) []byte to io.Reader type
+9.5k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+7.7k Golang : Qt splash screen with delay example
+6.5k Golang : Decode XML data from RSS feed
+20.9k Golang : Convert string slice to struct and access with reflect example
+35.5k Golang : Validate IP address
+3.2k Java : Get FX sentiment from website example
+9.2k Javascript : Read/parse JSON data from HTTP response
+12.9k Golang : Get constant name from value
+7.7k Golang : How To Use Panic and Recover