ChainSafe / ChainSafe/gossamer

refactor: Prefer strconv.Itoa over fmt.Sprint

Open
#3,981 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
454
Forks
144
PR merge metrics
No merged PRs in 30d

Description

## Issue summary
strconv.Itoa is faster than fmt.Sprint and is preferred for converting integers to strings. The example below demonstrates the difference between them.

```go
func BenchmarkStrconv(b *testing.B) {
for j := 0; j < b.N; j++ {
_ = strconv.Itoa(80) //BenchmarkStrconv-16 508842183 2.283 ns/op
}
}
```
vs

```go
func BenchmarkFMT(b *testing.B) {
for j := 0; j < b.N; j++ {
_ = fmt.Sprint(80) // BenchmarkFMT-16 23801236 52.26 ns/op
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.