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.8k Golang : How to verify input is rune?
+18.7k Golang : Read input from console line
+8.7k Golang : Populate or initialize struct with values example
+4.9k Golang : Customize scanner.Scanner to treat dash as part of identifier
+12k Golang : How to display image file or expose CSS, JS files from localhost?
+19.4k Golang : Set or Add HTTP Request Headers
+18.4k Golang : Implement getters and setters
+28.4k Golang : Detect (OS) Operating System
+9.2k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+30.9k Golang : bufio.NewReader.ReadLine to read file line by line
+10.7k Golang : How to transmit update file to client by HTTP request example
+19k Golang : Get RGBA values of each image pixel