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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [runtime/] [mfinal_test.go] - Blame information for rev 848

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package runtime_test
6
 
7
import (
8
        "runtime"
9
        "sync"
10
        "sync/atomic"
11
        "testing"
12
)
13
 
14
func fin(v *int) {
15
}
16
 
17
func BenchmarkFinalizer(b *testing.B) {
18
        const CallsPerSched = 1000
19
        procs := runtime.GOMAXPROCS(-1)
20
        N := int32(b.N / CallsPerSched)
21
        var wg sync.WaitGroup
22
        wg.Add(procs)
23
        for p := 0; p < procs; p++ {
24
                go func() {
25
                        var data [CallsPerSched]*int
26
                        for i := 0; i < CallsPerSched; i++ {
27
                                data[i] = new(int)
28
                        }
29
                        for atomic.AddInt32(&N, -1) >= 0 {
30
                                runtime.Gosched()
31
                                for i := 0; i < CallsPerSched; i++ {
32
                                        runtime.SetFinalizer(data[i], fin)
33
                                }
34
                                for i := 0; i < CallsPerSched; i++ {
35
                                        runtime.SetFinalizer(data[i], nil)
36
                                }
37
                        }
38
                        wg.Done()
39
                }()
40
        }
41
        wg.Wait()
42
}
43
 
44
func BenchmarkFinalizerRun(b *testing.B) {
45
        const CallsPerSched = 1000
46
        procs := runtime.GOMAXPROCS(-1)
47
        N := int32(b.N / CallsPerSched)
48
        var wg sync.WaitGroup
49
        wg.Add(procs)
50
        for p := 0; p < procs; p++ {
51
                go func() {
52
                        for atomic.AddInt32(&N, -1) >= 0 {
53
                                runtime.Gosched()
54
                                for i := 0; i < CallsPerSched; i++ {
55
                                        v := new(int)
56
                                        runtime.SetFinalizer(v, fin)
57
                                }
58
                                runtime.GC()
59
                        }
60
                        wg.Done()
61
                }()
62
        }
63
        wg.Wait()
64
}

powered by: WebSVN 2.1.0

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