File tree Expand file tree Collapse file tree 3 files changed +29
-27
lines changed Expand file tree Collapse file tree 3 files changed +29
-27
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ tree/tree
7
7
8
8
# Test binary, build with `go test -c`
9
9
* .test
10
+ tst
10
11
11
12
# save data
12
13
* .gob
Original file line number Diff line number Diff line change 4
4
5
5
// func oneIfTrue(x, y float32) float32
6
6
TEXT ·oneIfTrue(SB),NOSPLIT,$0
7
- MOVQ x+0 (FP), CX // put first arg in the CX register
8
- MOVQ y+4 (FP), SI // put second arg in SI register
9
- CMPQ CX, SI // see if first arg equals second arg
10
- JE RONE // when equal, change the return value
11
- MOVQ $0 , ret +8 (FP) // default 0 as the return value
7
+ MOVSS x+0 (FP), X0 // put first arg in a register
8
+ MOVSS y+4 (FP), X1 // put second arg in a register
9
+ UCOMISS X0, X1
10
+ JNE NOTEQ // when not equal return 0
11
+ MOVQ $0x3f800000 , ret +8 (FP) // when equal return 0
12
12
RET
13
- RONE :
14
- MOVQ $1 , ret +8 (FP) // move 1 to the return value
13
+ NOTEQ :
14
+ MOVQ $0x00000000 , ret +8 (FP) // move 0 to the return value
15
15
RET
Original file line number Diff line number Diff line change @@ -39,25 +39,26 @@ func TestOit(t *testing.T) {
39
39
}
40
40
41
41
func BenchmarkOit (b * testing.B ) {
42
- var count float32
43
- var a float32
44
- var v float32
45
- for i := 0 ; i < b .N ; i ++ {
46
- a = rand .Float32 ()
47
- v = rand .Float32 ()
48
- count += oneIfTrue (a , v )
49
- }
50
- }
51
-
52
- func BenchmarkIf (b * testing.B ) {
53
- var count float32
54
- var a float32
55
- var v float32
56
- for i := 0 ; i < b .N ; i ++ {
57
- a = rand .Float32 ()
58
- v = rand .Float32 ()
59
- if a == v {
60
- count ++
42
+ b .Run ("oneIfTrue" , func (b * testing.B ) {
43
+ var count float32
44
+ var a float32
45
+ var v float32
46
+ for i := 0 ; i < b .N ; i ++ {
47
+ a = rand .Float32 ()
48
+ v = rand .Float32 ()
49
+ count += oneIfTrue (a , v )
61
50
}
62
- }
51
+ })
52
+ b .Run ("regular conditional" , func (b * testing.B ) {
53
+ var count float32
54
+ var a float32
55
+ var v float32
56
+ for i := 0 ; i < b .N ; i ++ {
57
+ a = rand .Float32 ()
58
+ v = rand .Float32 ()
59
+ if a == v {
60
+ count ++
61
+ }
62
+ }
63
+ })
63
64
}
You can’t perform that action at this time.
0 commit comments