ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since a254fa56 was
26fd986,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
update benchmarks for concurrency paper
|
-
Property mode set to
100644
|
File size:
721 bytes
|
Line | |
---|
1 | package main |
---|
2 | |
---|
3 | import ( |
---|
4 | "fmt" |
---|
5 | "time" |
---|
6 | "os" |
---|
7 | "strconv" |
---|
8 | ) |
---|
9 | |
---|
10 | func main() { |
---|
11 | shake := make( chan bool ) |
---|
12 | ch := make( chan int ) |
---|
13 | |
---|
14 | acceptor := func(times int) { |
---|
15 | var v int |
---|
16 | v += 1 // need usage |
---|
17 | for i := 0; i < times; i += 1 { |
---|
18 | select { |
---|
19 | case v = <- ch : |
---|
20 | } |
---|
21 | } |
---|
22 | shake <- true // indicate completion |
---|
23 | } |
---|
24 | |
---|
25 | var times int = 10000000 |
---|
26 | if len( os.Args ) > 2 { os.Exit( 1 ) } |
---|
27 | if len( os.Args ) == 2 { times, _ = strconv.Atoi(os.Args[1]) } |
---|
28 | |
---|
29 | go acceptor( times ) |
---|
30 | start := time.Now() |
---|
31 | for i := 0; i < times; i += 1 { |
---|
32 | ch <- 1 |
---|
33 | } |
---|
34 | end := time.Now() |
---|
35 | fmt.Printf("%d\n", end.Sub(start) / time.Duration(times)) |
---|
36 | <- shake |
---|
37 | } |
---|
38 | |
---|
39 | // Local Variables: // |
---|
40 | // tab-width: 4 // |
---|
41 | // compile-command: "go run goroutine.go" // |
---|
42 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.