mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-02-09 12:03:12 +08:00
* perf(loader): reuse cached parsed templates in `(*Store).areWorkflowOrTemplatesValid`, which is being called during template `-validate`-ion. Signed-off-by: Dwi Siswanto <git@dw1.io> * refactor(testutils): optionally assign template info in `NewMockExecuterOptions`, which is not required for specific case, like when we want to `(*Store).ValidateTemplates`. Signed-off-by: Dwi Siswanto <git@dw1.io> * test(loader): adds `(*Store).ValidateTemplates` bench Signed-off-by: Dwi Siswanto <git@dw1.io> * refactor(templates): adds fast read parser Signed-off-by: Dwi Siswanto <git@dw1.io> * test(templates): adds `Parser*` benchs Signed-off-by: Dwi Siswanto <git@dw1.io> * chore(templates): satisfy lints Signed-off-by: Dwi Siswanto <git@dw1.io> * revert(templates): rm fast read parser Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io>
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package loader_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/projectdiscovery/gologger"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/disk"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/loader"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/loader/workflow"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
|
|
)
|
|
|
|
func BenchmarkStoreValidateTemplates(b *testing.B) {
|
|
options := testutils.DefaultOptions.Copy()
|
|
options.Logger = &gologger.Logger{}
|
|
testutils.Init(options)
|
|
|
|
catalog := disk.NewCatalog(config.DefaultConfig.TemplatesDirectory)
|
|
executerOpts := testutils.NewMockExecuterOptions(options, nil)
|
|
executerOpts.Parser = templates.NewParser()
|
|
|
|
workflowLoader, err := workflow.NewLoader(executerOpts)
|
|
if err != nil {
|
|
b.Fatalf("could not create workflow loader: %s", err)
|
|
}
|
|
executerOpts.WorkflowLoader = workflowLoader
|
|
|
|
loaderCfg := loader.NewConfig(options, catalog, executerOpts)
|
|
|
|
store, err := loader.New(loaderCfg)
|
|
if err != nil {
|
|
b.Fatalf("could not create store: %s", err)
|
|
}
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
for b.Loop() {
|
|
_ = store.ValidateTemplates()
|
|
}
|
|
}
|