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.5k Golang : How to capture return values from goroutines?
+4.4k Facebook : How to force facebook to scrape latest URL link data?
+11.7k Golang : Tutorial on loading GOB and PEM files
+26.5k Golang : Get first few and last few characters from string
+5k Golang : How to detect if a sentence ends with a punctuation?
+4.4k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+18.9k Golang : How to get time zone and load different time zone?
+12.6k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+3.7k Responsive Google Adsense
+19.2k Golang : Join arrays or slices example
+6.6k Golang : Convert word to its plural form example