-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark_test.go
60 lines (51 loc) · 3.15 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
53
54
55
56
57
58
59
60
package iab_tcf
import (
"time"
"github.com/montanaflynn/stats"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gmeasure"
)
type data struct {
consent string
result string
}
var _ = Describe("performance", func() {
var (
experiment *gmeasure.Experiment
times = gmeasure.SamplingConfig{N: 1000}
testConsentV1 = data{
consent: "BOlLbqtOlLbqtAVABADECg-AAAApp7v______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-3zd4u_1vf99yfm1-7etr3tp_87ues2_Xur__79__3z3_9phP78k89r7337Ew-v02",
result: "111101110111111111111111111111111111111111111111111110111111111111111111111111111111111111111110110111011001111111100111010111111111110111111111101111111111111111111011111011101111011110011111111111111110110111111111110010111111111101111111111111011111111111111111110111011111111111011011111001101110111100010111011111111010110111101111111110111110111001001111110011011010111111011101101111010110110101111011110110110100111111111110011101110111001111010110011011011111101011110111010101111111111111111101111110111111111111111011111001111011111111111110110100110000100111111101111110010010011110011110110101111101111011111011111101100010011000011111010111111010011011",
}
testConsentV2 = data{
consent: "COxR03kOxR1CqBcABCENAgCMAP_AAH_AAAqIF3EXySoGY2thI2YVFxBEIYwfJxyigMgChgQIsSwNQIeFLBoGLiAAHBGYJAQAGBAEEACBAQIkHGBMCQAAgAgBiRCMQEGMCzNIBIBAggEbY0FACCVmHkHSmZCY7064O__QLuIJEFQMAkSBAIACLECIQwAQDiAAAYAlAAABAhIaAAgIWBQEeAAAACAwAAgAAABBAAACAAQAAICIAAABAAAgAiAQAAAAGgIQAACBABACRIAAAEANCAAgiCEAQg4EAo4AAA",
result: "010001011111001001001010100000011001100011011010110110000100100011011001100001010100010111000100000100010000100001100011000001111100100111000111001010001010000000110010000000001010000110000001000000100010110001001011000000110101000000100001111000010100101100000110100000011000101110001000000000000000011100000100011001100000100100000001000000000000011000000100000000010000010000000000001000000100000001000000100010010000011100011000000100110000001001000000000000000010000000000010000000000110001001000100001000110001000000010000011000110000001011001100110100100000000100100000000100000010000010000000010001101101100011010000010100000000001000001001010110011000011110010000011101001010011001100100001001100011101111010011101011100000111011111111111101",
}
)
BeforeEach(func() {
experiment = gmeasure.NewExperiment("consent speed")
})
Context("custom parser", func() {
var run = func(consent string, expected string) func(_ int) {
return func(_ int) {
output, err := NewConsent(consent)
Expect(err).NotTo(HaveOccurred())
Expect(output.GetConsentBitstring()).To(Equal(expected))
}
}
var assert = func() {
measurements := experiment.Get("runtime")
p99, _ := stats.Percentile(stats.LoadRawData(measurements.Durations), 99)
Expect(p99).Should(BeNumerically("<", 2000*time.Millisecond), "it shouldn't take too long.")
}
It("is fast with v1", func() {
experiment.SampleDuration("runtime", run(testConsentV1.consent, testConsentV1.result), times)
assert()
})
It("is fast with v2", func() {
experiment.SampleDuration("runtime", run(testConsentV2.consent, testConsentV2.result), times)
assert()
})
})
})