|
| 1 | +package main_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + "net/http/httptest" |
| 6 | + "testing" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/projectdiscovery/goflags" |
| 10 | + "github.com/projectdiscovery/gologger" |
| 11 | + "github.com/projectdiscovery/gologger/levels" |
| 12 | + "github.com/projectdiscovery/nuclei/v3/internal/runner" |
| 13 | + "github.com/projectdiscovery/nuclei/v3/pkg/types" |
| 14 | +) |
| 15 | + |
| 16 | +func BenchmarkRunEnumeration(b *testing.B) { |
| 17 | + dummyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 18 | + w.WriteHeader(http.StatusNoContent) |
| 19 | + })) |
| 20 | + defer dummyServer.Close() |
| 21 | + |
| 22 | + options := &types.Options{ |
| 23 | + RemoteTemplateDomainList: goflags.StringSlice{ |
| 24 | + "cloud.projectdiscovery.io", |
| 25 | + }, |
| 26 | + ProjectPath: "/tmp", |
| 27 | + Targets: goflags.StringSlice{dummyServer.URL}, |
| 28 | + StatsInterval: 5, |
| 29 | + MetricsPort: 9092, |
| 30 | + MaxHostError: 30, |
| 31 | + NoHostErrors: true, |
| 32 | + BulkSize: 25, |
| 33 | + TemplateThreads: 25, |
| 34 | + HeadlessBulkSize: 10, |
| 35 | + HeadlessTemplateThreads: 10, |
| 36 | + Timeout: 10, |
| 37 | + Retries: 1, |
| 38 | + RateLimit: 150, |
| 39 | + RateLimitDuration: time.Duration(time.Second), |
| 40 | + RateLimitMinute: 0, |
| 41 | + PageTimeout: 20, |
| 42 | + InteractionsCacheSize: 5000, |
| 43 | + InteractionsPollDuration: 5, |
| 44 | + InteractionsEviction: 60, |
| 45 | + InteractionsCoolDownPeriod: 5, |
| 46 | + MaxRedirects: 10, |
| 47 | + Silent: true, |
| 48 | + VarDumpLimit: 255, |
| 49 | + JSONRequests: true, |
| 50 | + StoreResponseDir: "output", |
| 51 | + InputFileMode: "list", |
| 52 | + ResponseReadSize: 0, |
| 53 | + ResponseSaveSize: 1048576, |
| 54 | + InputReadTimeout: time.Duration(3 * time.Minute), |
| 55 | + UncoverField: "ip:port", |
| 56 | + UncoverLimit: 100, |
| 57 | + UncoverRateLimit: 60, |
| 58 | + ScanStrategy: "auto", |
| 59 | + FuzzAggressionLevel: "low", |
| 60 | + FuzzParamFrequency: 10, |
| 61 | + TeamID: "none", |
| 62 | + JsConcurrency: 120, |
| 63 | + PayloadConcurrency: 25, |
| 64 | + ProbeConcurrency: 50, |
| 65 | + LoadHelperFileFunction: types.DefaultOptions().LoadHelperFileFunction, |
| 66 | + // DialerKeepAlive: time.Duration(0), |
| 67 | + // DASTServerAddress: "localhost:9055", |
| 68 | + } |
| 69 | + |
| 70 | + runner.ParseOptions(options) |
| 71 | + |
| 72 | + // Disable logging to reduce benchmark noise. |
| 73 | + gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent) |
| 74 | + |
| 75 | + nucleiRunner, err := runner.New(options) |
| 76 | + if err != nil { |
| 77 | + b.Fatalf("failed to create runner: %s", err) |
| 78 | + } |
| 79 | + |
| 80 | + b.ResetTimer() |
| 81 | + |
| 82 | + for i := 0; i < b.N; i++ { |
| 83 | + if err := nucleiRunner.RunEnumeration(); err != nil { |
| 84 | + b.Fatalf("RunEnumeration failed: %s", err) |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments