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
+6.9k Golang : Get Alexa ranking data example
+12.4k Golang : Add ASCII art to command line application launching process
+40.7k Golang : How to check if a string contains another sub-string?
+9.9k Golang : Edge detection with Sobel method
+17.7k Golang : Get all upper case or lower case characters from string example
+18k Golang : How to remove certain lines from a file
+7.4k Gogland : Where to put source code files in package directory for rookie
+11.1k Android Studio : Create custom icons for your application example
+19.3k Golang : Close channel after ticker stopped example
+5.3k Golang : If else example and common mistake
+12.9k Golang : Convert(cast) int to int64
+12k Golang : List running EC2 instances and descriptions