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
+25.1k Golang : Create PDF file from HTML file
+32.2k Golang : Validate email address with regular expression
+18.2k Golang : Put UTF8 text on OpenCV video capture image frame
+39.7k Golang : Remove dashes(or any character) from string
+23.2k Golang : Randomly pick an item from a slice/array example
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+12.5k Elastic Search : Return all records (higher than default 10)
+9.8k Golang : Load ASN1 encoded DSA public key PEM file example
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+15.3k Golang : Get HTTP protocol version example
+8.7k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+18k Golang : How to log each HTTP request to your web server?