Skip to content

Commit

Permalink
docs: update benchmarks and write about dig changes
Browse files Browse the repository at this point in the history
  • Loading branch information
42atomys committed May 9, 2024
1 parent b9f4baf commit e3d9459
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 19 additions & 0 deletions SPRIG_TO_SPROUT_CHANGES_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
23 changes: 21 additions & 2 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
2 changes: 1 addition & 1 deletion benchmarks/allFunctions.sprig.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/allFunctions.sprout.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}}
Expand Down

0 comments on commit e3d9459

Please sign in to comment.