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
+9.8k Golang : How to determine a prime number?
+10k Golang : How to pipe input data to executing child process?
+7.7k Golang : Gonum standard normal random numbers example
+6.1k Golang : Check if one string(rune) is permutation of another string(rune)
+7.9k Golang : How to get username from email address
+4.6k Python : Print unicode escape characters and string
+11.7k Golang : http.Get example
+7.3k Golang : Ackermann function example
+15.7k Golang : Find file size(disk usage) with filepath.Walk
+16k Golang : How to save log messages to file?
+3.7k JavaScript: Add marker function on Google Map
+13.5k Golang : Find commonalities in two slices or arrays example