forked from statsig-io/go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
52 lines (44 loc) · 1.33 KB
/
benchmark_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
48
49
50
51
52
package statsig
import (
"fmt"
"os"
"testing"
"time"
)
func TestBenchmarkLocalMode(t *testing.T) {
secret = os.Getenv("test_api_key")
defaultDuration := measureDuration(func() {
options := &Options{LocalMode: false}
NewClientWithOptions(secret, options)
})
localModeDuration := measureDuration(func() {
options := &Options{LocalMode: true}
NewClientWithOptions(secret, options)
})
fmt.Printf("Default duration: %s\n", defaultDuration)
fmt.Printf("Local mode duration: %s\n", localModeDuration)
if defaultDuration < localModeDuration {
t.Error("Expected faster initialization with local mode")
}
}
func TestBenchmarkUAParser(t *testing.T) {
secret = os.Getenv("test_api_key")
defaultDuration := measureDuration(func() {
options := &Options{LocalMode: true}
NewClientWithOptions(secret, options)
})
disabledDuration := measureDuration(func() {
options := &Options{LocalMode: true, UAParserOptions: UAParserOptions{Disabled: true}}
NewClientWithOptions(secret, options)
})
fmt.Printf("UA Parser default duration: %s\n", defaultDuration)
fmt.Printf("UA Parser disabled duration: %s\n", disabledDuration)
if defaultDuration < disabledDuration {
t.Error("Expected faster initialization with disabled UA parsser")
}
}
func measureDuration(f func()) time.Duration {
start := time.Now()
f()
return time.Since(start)
}