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

Subversion Repositories openrisc

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

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
package runtime_test
5
 
6
import "testing"
7
 
8
const N = 20
9
 
10
func BenchmarkAppend(b *testing.B) {
11
        b.StopTimer()
12
        x := make([]int, 0, N)
13
        b.StartTimer()
14
        for i := 0; i < b.N; i++ {
15
                x = x[0:0]
16
                for j := 0; j < N; j++ {
17
                        x = append(x, j)
18
                }
19
        }
20
}
21
 
22
func BenchmarkAppendSpecialCase(b *testing.B) {
23
        b.StopTimer()
24
        x := make([]int, 0, N)
25
        b.StartTimer()
26
        for i := 0; i < b.N; i++ {
27
                x = x[0:0]
28
                for j := 0; j < N; j++ {
29
                        if len(x) < cap(x) {
30
                                x = x[:len(x)+1]
31
                                x[len(x)-1] = j
32
                        } else {
33
                                x = append(x, j)
34
                        }
35
                }
36
        }
37
}
38
 
39
var x []int
40
 
41
func f() int {
42
        x[:1][0] = 3
43
        return 2
44
}
45
 
46
func TestSideEffectOrder(t *testing.T) {
47
        x = make([]int, 0, 10)
48
        x = append(x, 1, f())
49
        if x[0] != 1 || x[1] != 2 {
50
                t.Error("append failed: ", x[0], x[1])
51
        }
52
}

powered by: WebSVN 2.1.0

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