Skip to content

Improve ToString by 20%#62

Merged
ReneWerner87 merged 4 commits intogofiber:masterfrom
Fenny:master
Feb 9, 2024
Merged

Improve ToString by 20%#62
ReneWerner87 merged 4 commits intogofiber:masterfrom
Fenny:master

Conversation

@Fenny
Copy link
Member

@Fenny Fenny commented Feb 8, 2024

  • Avoid unnecessary pointer dereferencing in convert.go#ToString
  • Add all types in ToString tests and benchmarks
ok  	github.com/gofiber/utils/v2	2.314s	coverage: 75.4% of statements
**Before**
Benchmark_ToString-24            3499046               339.2 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            3552510               336.8 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            3589656               335.2 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            3564043               337.8 ns/op            96 B/op          6 allocs/op
**After**
Benchmark_ToString-24            4211290               285.7 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            4296464               282.5 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            4279908               283.5 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            4216419               283.5 ns/op            96 B/op          6 allocs/op

Avoid unnecessary pointer dereferencing

#Before
```
Benchmark_ToString-24            3499046               339.2 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            3552510               336.8 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            3589656               335.2 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            3564043               337.8 ns/op            96 B/op          6 allocs/op
```

#After
```
Benchmark_ToString-24            4211290               285.7 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            4296464               282.5 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            4279908               283.5 ns/op            96 B/op          6 allocs/op
Benchmark_ToString-24            4216419               283.5 ns/op            96 B/op          6 allocs/op
```
@gaby
Copy link
Member

gaby commented Feb 9, 2024

The previous benchmark had 10x more performance. https://github.com/gofiber/utils/actions/runs/7753577848/job/21145172120

Is this related to the change in the benchmark code?

@Fenny
Copy link
Member Author

Fenny commented Feb 9, 2024

The previous benchmark had 10x more performance. https://github.com/gofiber/utils/actions/runs/7753577848/job/21145172120

Is this related to the change in the benchmark code?

Yes, see #62 (comment)

@ReneWerner87 ReneWerner87 merged commit 8e706d8 into gofiber:master Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants