Created
August 17, 2016 12:58
-
-
Save bohdantrotsenko/e2ce62e5fb5f09ff39aa0ca6242454d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
) | |
const N = 300 | |
const P = 20 | |
const timeFormat = "15:04:05.0000" | |
func heavy(res chan<- string) { | |
start := time.Now() | |
var sum int64 = 0 | |
for i1 := 0; i1 < N; i1++ { | |
for i2 := 0; i2 < N; i2++ { | |
for i3 := 0; i3 < N; i3++ { | |
for i4 := 0; i4 < N; i4++ { | |
sum++ | |
} | |
} | |
} | |
} | |
n := int64(N) | |
n = n * n | |
n = n * n | |
if sum != n { | |
fmt.Println("Ooops") | |
} | |
end := time.Now() | |
dur := end.Sub(start) | |
res <- fmt.Sprintf("started %s, ended %s (lasted %f)", start.Format(timeFormat), end.Format(timeFormat), dur.Seconds()) | |
} | |
func main() { | |
res := make(chan string, P) | |
for i := 0; i < P; i++ { | |
go heavy(res) | |
} | |
fmt.Println(">>>") | |
for i := 0; i < P; i++ { | |
fmt.Println(<-res) | |
} | |
fmt.Println("<<<") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment