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
+15.5k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+11.3k Android Studio : Create custom icons for your application example
+13.9k Golang : Google Drive API upload and rename example
+21.5k SSL : How to check if current certificate is sha1 or sha2
+8.1k Golang : Add build version and other information in executables
+5.7k Golang : Find change in a combination of coins example
+9.6k Golang : List available AWS regions
+7.4k Gogland : Single File versus Go Application Run Configurations
+12.5k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+20.3k Golang : Pipe output from one os.Exec(shell command) to another command
+10.4k Golang : Get local time and equivalent time in different time zone
+7.5k Golang : Convert(cast) io.Reader type to string