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
+32.4k Golang : How to check if slice or array is empty?
+7.1k Golang : Variadic function arguments sanity check example
+13.6k Golang : Missing Bazaar command
+35k Golang : Display float in 2 decimal points and rounding up or down
+18.3k Golang : Check if os.Stdin input data is piped or from terminal
+7.1k Golang : Oanda bot with Telegram and RSI example
+12.9k Golang : Google Drive API upload and rename example
+18.3k Golang : Determine if directory is empty with os.File.Readdir() function
+13.7k Golang : Get all local users and print out their home directory, description and group id
+50.4k Golang : How to get struct field and value by name
+18k Golang : Execute shell command
+14.2k Golang : Delete certain files in a directory