Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/protocols/common/generators/options_bench_test.go
2843 views
1
package generators
2
3
import (
4
"testing"
5
6
"github.com/projectdiscovery/goflags"
7
"github.com/projectdiscovery/nuclei/v3/pkg/types"
8
)
9
10
func BenchmarkBuildPayloadFromOptions(b *testing.B) {
11
// Setup options with vars and env vars
12
vars := goflags.RuntimeMap{}
13
_ = vars.Set("key1=value1")
14
_ = vars.Set("key2=value2")
15
_ = vars.Set("key3=value3")
16
_ = vars.Set("key4=value4")
17
_ = vars.Set("key5=value5")
18
19
opts := &types.Options{
20
Vars: vars,
21
EnvironmentVariables: true, // This adds more entries
22
}
23
24
b.Run("Sequential", func(b *testing.B) {
25
ClearOptionsPayloadMap(opts)
26
27
b.ReportAllocs()
28
for b.Loop() {
29
_ = BuildPayloadFromOptions(opts)
30
}
31
})
32
33
b.Run("Parallel", func(b *testing.B) {
34
ClearOptionsPayloadMap(opts)
35
36
b.ReportAllocs()
37
b.RunParallel(func(pb *testing.PB) {
38
for pb.Next() {
39
m := BuildPayloadFromOptions(opts)
40
// Simulate typical usage - read a value
41
_ = m["key1"]
42
}
43
})
44
})
45
}
46
47