-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (52 loc) · 1.44 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"log"
"math/rand"
"time"
"example.com/lab3/blocking"
"example.com/lab3/nonblocking"
"example.com/lab3/single"
)
const (
sizeMultiplier = 100000
N = 23
multipleOf = 17
test = 0
)
var (
arraySize = sizeMultiplier * N
)
func FillArray(array []int64) {
s1 := rand.NewSource(time.Now().UnixNano())
r := rand.New(s1)
for i := range array {
array[i] = r.Int63()
}
}
func main() {
fmt.Println("start")
if test == 1 {
arraySize = 30
}
array := make([]int64, arraySize)
FillArray(array)
if test == 1 {
fmt.Println(array)
}
start := time.Now()
fmt.Println("single: ", single.CountMultiples(multipleOf, array))
fmt.Println(time.Since(start))
start = time.Now()
fmt.Println("blocking: ", blocking.CountMultiples(multipleOf, array))
fmt.Println(time.Since(start))
start = time.Now()
fmt.Println("nonblocking: ", nonblocking.CountMultiples(multipleOf, array))
fmt.Println(time.Since(start))
if single.CountMultiples(multipleOf, array) != nonblocking.CountMultiples(multipleOf, array) {
log.Fatalln("error when comparing (nonblocking): ", single.CountMultiples(multipleOf, array), " != ", nonblocking.CountMultiples(multipleOf, array))
}
if single.CountMultiples(multipleOf, array) != blocking.CountMultiples(multipleOf, array) {
log.Fatalln("error when comparing (blocking): ", single.CountMultiples(multipleOf, array), " != ", blocking.CountMultiples(multipleOf, array))
}
}