File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1
1
package assert
2
2
3
3
import (
4
+ "bytes"
5
+ "fmt"
4
6
"testing"
5
7
)
6
8
@@ -15,6 +17,17 @@ func TestGoid(t *testing.T) {
15
17
}
16
18
}
17
19
20
+ func Test_oldGoid (t * testing.T ) {
21
+ t .Parallel ()
22
+ stackBytes := []byte (`goroutine 518 [running]:
23
+ ` )
24
+
25
+ id := oldGoid (stackBytes )
26
+ if id != 518 {
27
+ t .Fail ()
28
+ }
29
+ }
30
+
18
31
func BenchmarkGoid (b * testing.B ) {
19
32
_ = []byte (`goroutine 518 [running]:
20
33
` )
@@ -32,3 +45,20 @@ func BenchmarkGoid_MyByteToInt(b *testing.B) {
32
45
_ = myByteToInt (stackBytes [10 :])
33
46
}
34
47
}
48
+
49
+ func oldGoid (buf []byte ) (id int ) {
50
+ _ , err := fmt .Fscanf (bytes .NewReader (buf ), "goroutine %d" , & id )
51
+ if err != nil {
52
+ panic ("cannot get goroutine id: " + err .Error ())
53
+ }
54
+ return id
55
+ }
56
+
57
+ func BenchmarkGoid_Old (b * testing.B ) {
58
+ stackBytes := []byte (`goroutine 518 [running]:
59
+ ` )
60
+
61
+ for n := 0 ; n < b .N ; n ++ {
62
+ _ = oldGoid (stackBytes )
63
+ }
64
+ }
You can’t perform that action at this time.
0 commit comments