Last active
March 10, 2019 00:27
-
-
Save 1a1a11a/a1b95f1a4939bf9480bbc957e6c17f71 to your computer and use it in GitHub Desktop.
some benchmark related to golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"sync" | |
) | |
func main() { | |
wg := sync.WaitGroup{} | |
x := 0 | |
channel := make(chan int, 20000000) | |
mtx := sync.Mutex{} | |
for i := 0; i < 1000000; i++ { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
mtx.Lock() | |
x++ | |
mtx.Unlock() | |
channel <- x | |
}() | |
} | |
wg.Wait() | |
fmt.Println("x ", x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On a 2015 MacBook Pro 15,