-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
47 lines (41 loc) · 1011 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"testing"
"github.com/maverickwoo/go-vtable-demo/shape"
"github.com/maverickwoo/go-vtable-demo/shape/rectangle"
"github.com/maverickwoo/go-vtable-demo/shape/square"
)
func BenchmarkRectangleAreaStatic(b *testing.B) {
b.StopTimer()
var concrete *rectangle.T = rectangle.New("sq", 6, 7)
b.StartTimer()
for n := 0; n < b.N; n++ {
_ = concrete.Area()
}
}
func BenchmarkRectangleAreaDynamic(b *testing.B) {
b.StopTimer()
var concrete *rectangle.T = rectangle.New("sq", 6, 7)
var virtual *shape.T = &concrete.T
b.StartTimer()
for n := 0; n < b.N; n++ {
_ = virtual.Area()
}
}
func BenchmarkSquareAreaStatic(b *testing.B) {
b.StopTimer()
var concrete *square.T = square.New("sq", 8)
b.StartTimer()
for n := 0; n < b.N; n++ {
_ = concrete.Area()
}
}
func BenchmarkSquareAreaDynamic(b *testing.B) {
b.StopTimer()
var concrete *square.T = square.New("sq", 8)
var virtual *shape.T = &concrete.T
b.StartTimer()
for n := 0; n < b.N; n++ {
_ = virtual.Area()
}
}