Logo
Explore Help
Register Sign In
External/nuclei
1
0
Fork 0
You've already forked nuclei
mirror of https://github.com/projectdiscovery/nuclei.git synced 2025-12-18 00:25:26 +00:00
Code Issues Packages Projects Releases Wiki Activity
nuclei/v2/pkg/protocols/common/replacer/replacer_test.go

13 lines
328 B
Go
Raw Normal View History

Memory usage optimizations (#2350) * Replaced strings.Replaced with fasttemplate reducing allocations Custom template parsing logic was replaced with fasttemplate package for reducing allocations in the replacer.Replace hotpath leading to allocation reduction which accounted for 30% of total nuclei allocations. $ go test -bench=. -benchmem goos: darwin goarch: arm64 pkg: github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/replacer BenchmarkReplacer-8 837232 1422 ns/op 2112 B/op 31 allocs/op BenchmarkReplacerNew-8 3672765 320.3 ns/op 48 B/op 4 allocs/op * Fixed tests failing * Use pre-compiled map of DSL expressions * Reworked expression parsing logic to reduce memory allocations $ go test -bench=. -benchmem goos: darwin goarch: arm64 pkg: github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/expressions BenchmarkEvaluate-8 31560 37769 ns/op 31731 B/op 265 allocs/op BenchmarkEvaluateNew-8 109144 9621 ns/op 6253 B/op 116 allocs/op
2022-08-23 13:16:41 +05:30
package replacer
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestReplacerReplace(t *testing.T) {
replaced := Replace("{{test}} §hello§ {{data}}", map[string]interface{}{"test": "random", "hello": "world"})
require.Equal(t, "random world {{data}}", replaced, "could not get correct replaced data")
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.6 Page: 439ms Template: 3ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API