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
+24.2k Golang : Fix type interface{} has no field or no methods and type assertions example
+11.2k Golang : Generate random elements without repetition or duplicate
+17.6k Golang : Check if IP address is version 4 or 6
+5.4k Golang : The Tao of importing package
+9.5k Golang : Find the length of big.Int variable example
+6.4k PHP : Get client IP address
+22.4k Golang : Match strings by wildcard patterns with filepath.Match() function
+20.1k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+7.7k Golang : Rot13 and Rot5 algorithms example
+5k Golang : A program that contain another program and executes it during run-time
+19.5k Golang : Calculate entire request body length during run time
+12.6k Golang : How to check if a string starts or ends with certain characters or words?