OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [chan/] [select2.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2010 The Go Authors.  All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
package main
8
 
9
import "runtime"
10
 
11
func sender(c chan int, n int) {
12
        for i := 0; i < n; i++ {
13
                c <- 1
14
        }
15
}
16
 
17
func receiver(c, dummy chan int, n int) {
18
        for i := 0; i < n; i++ {
19
                select {
20
                case <-c:
21
                        // nothing
22
                case <-dummy:
23
                        panic("dummy")
24
                }
25
        }
26
}
27
 
28
func main() {
29
        runtime.MemProfileRate = 0
30
 
31
        c := make(chan int)
32
        dummy := make(chan int)
33
 
34
        // warm up
35
        go sender(c, 100000)
36
        receiver(c, dummy, 100000)
37
        runtime.GC()
38
        memstats := new(runtime.MemStats)
39
        runtime.ReadMemStats(memstats)
40
        alloc := memstats.Alloc
41
 
42
        // second time shouldn't increase footprint by much
43
        go sender(c, 100000)
44
        receiver(c, dummy, 100000)
45
        runtime.GC()
46
        runtime.ReadMemStats(memstats)
47
 
48
        if memstats.Alloc-alloc > 1e5 {
49
                println("BUG: too much memory for 100,000 selects:", memstats.Alloc-alloc)
50
        }
51
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.