diff --git a/README.md b/README.md index 8f9cb84..5b7098f 100644 --- a/README.md +++ b/README.md @@ -184,17 +184,19 @@ To see all the benchmarks, please refer to the [benchmarks](benchmarks/README.md goos: linux goarch: amd64 pkg: sprout_benchmarks -cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz -BenchmarkSprig-12 1 3869134593 ns/op 45438616 B/op 24098 allocs/op -BenchmarkSprout-12 1 1814126036 ns/op 38284040 B/op 11627 allocs/op +cpu: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz +BenchmarkSprig-16 1 2152506421 ns/op 44671136 B/op 21938 allocs/op +BenchmarkSprout-16 1 1020721871 ns/op 37916984 B/op 11173 allocs/op PASS -ok sprout_benchmarks 5.910s +ok sprout_benchmarks 3.720s ``` -**Time improvement**: 53.1% -**Memory improvement**: 15.7% +**Time improvement**: ((2152506421 - 1020721871) / 2152506421) * 100 = 52.6% +**Memory improvement**: ((44671136 - 37916984) / 44671136) * 100 = 15.1% -So, Sprout v0.2 is approximately 53.1% faster and uses 15.7% less memory than Sprig v3.2.3. 🚀 +So, Sprout v0.3 is approximately 52.6% faster and uses 15.1% less memory than Sprig v3.2.3. 🚀 + +You can see the full benchmark results [here](benchmarks/README.md). ## Development Philosophy (Currently in reflexion to create our) diff --git a/SPRIG_TO_SPROUT_CHANGES_NOTES.md b/SPRIG_TO_SPROUT_CHANGES_NOTES.md index de8b2f4..3d74912 100644 --- a/SPRIG_TO_SPROUT_CHANGES_NOTES.md +++ b/SPRIG_TO_SPROUT_CHANGES_NOTES.md @@ -80,3 +80,22 @@ Methods that previously caused a panic in Sprig : ## Base32Decode / Base64Decode - **Sprig**: Decoding functions return the error string when the input is not a valid base64 encoded string. - **Sprout**: Decoding functions return an empty string if the input is not a valid base64 encoded string, simplifying error handling. + +## Dig +> Consider the example dictionary defined as follows: +> ```go +> dict := map[string]any{ +> "a": map[string]any{ +> "b": 2, +> }, +> } +> ``` + +- **Sprig**: Previously, the `dig` function would return the last map in the access chain. +```go +{{ $dict | dig "a" "b" }} // Output: map[b:2] +``` +- **Sprout**: Now, the `dig` function returns the final object in the chain, regardless of its type (map, array, string, etc.). +```go +{{ $dict | dig "a" "b" }} // Output: 2 +``` diff --git a/benchmarks/README.md b/benchmarks/README.md index 4e67cbf..89429ed 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -1,6 +1,6 @@ # Benchmarks outputs -## Sprig v3.2.3 vs Sprout v0.1 +## Sprig v3.2.3 vs Sprout v0.2 ``` go test -count=1 -bench ^Benchmark -benchmem -cpuprofile cpu.out -memprofile mem.out goos: linux @@ -16,4 +16,23 @@ ok sprout_benchmarks 5.910s **Time improvement**: ((3869134593 - 1814126036) / 3869134593) * 100 = 53.1% **Memory improvement**: ((45438616 - 38284040) / 45438616) * 100 = 15.7% -So, Sprout v0.1 is approximately 53.1% faster and uses 15.7% less memory than Sprig v3.2.3. +So, Sprout v0.2 is approximately 53.1% faster and uses 15.7% less memory than Sprig v3.2.3. + +## Sprig v3.2.3 vs Sprout v0.3 + +``` +go test -count=1 -bench ^Benchmark -benchmem -cpuprofile cpu.out -memprofile mem.out +goos: linux +goarch: amd64 +pkg: sprout_benchmarks +cpu: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz +BenchmarkSprig-16 1 2152506421 ns/op 44671136 B/op 21938 allocs/op +BenchmarkSprout-16 1 1020721871 ns/op 37916984 B/op 11173 allocs/op +PASS +ok sprout_benchmarks 3.720s +``` + +**Time improvement**: ((2152506421 - 1020721871) / 2152506421) * 100 = 52.6% +**Memory improvement**: ((44671136 - 37916984) / 44671136) * 100 = 15.1% + +So, Sprout v0.3 is approximately 52.6% faster and uses 15.1% less memory than Sprig v3.2.3. diff --git a/benchmarks/allFunctions.sprig.tmpl b/benchmarks/allFunctions.sprig.tmpl index de2f5c2..44b37de 100644 --- a/benchmarks/allFunctions.sprig.tmpl +++ b/benchmarks/allFunctions.sprig.tmpl @@ -184,7 +184,7 @@ Without: {{without (list 1 2 3) 2}} Has: {{hasKey $dict "key"}} Slice: {{slice (list 1 2 3) 1 2}} Concat: {{concat (list 1 2) (list 3 4)}} -Dig: {{dict "a" 1 | dig "a" ""}} +Dig: {{ dig "b" "a" (dict "a" 1 "b" (dict "a" 2)) }} Chunk: {{list 1 2 3 4 5 | chunk 2}} {{/* Crypt Functions */}} diff --git a/benchmarks/allFunctions.sprout.tmpl b/benchmarks/allFunctions.sprout.tmpl index de2f5c2..44b37de 100644 --- a/benchmarks/allFunctions.sprout.tmpl +++ b/benchmarks/allFunctions.sprout.tmpl @@ -184,7 +184,7 @@ Without: {{without (list 1 2 3) 2}} Has: {{hasKey $dict "key"}} Slice: {{slice (list 1 2 3) 1 2}} Concat: {{concat (list 1 2) (list 3 4)}} -Dig: {{dict "a" 1 | dig "a" ""}} +Dig: {{ dig "b" "a" (dict "a" 1 "b" (dict "a" 2)) }} Chunk: {{list 1 2 3 4 5 | chunk 2}} {{/* Crypt Functions */}}