snapshot of https://github.com/uber-go/guide.git (master, 2026-09-15; blobs > 131072B omitted)

This commit is contained in:
upstream-mirror
2026-09-15 21:54:05 +05:00
commit a9c6c3ea36
73 changed files with 8782 additions and 0 deletions

39
src/strconv.md Normal file
View File

@@ -0,0 +1,39 @@
# Prefer strconv over fmt
When converting primitives to/from strings, `strconv` is faster than
`fmt`.
<table>
<thead><tr><th>Bad</th><th>Good</th></tr></thead>
<tbody>
<tr><td>
```go
for i := 0; i < b.N; i++ {
s := fmt.Sprint(rand.Int())
}
```
</td><td>
```go
for i := 0; i < b.N; i++ {
s := strconv.Itoa(rand.Int())
}
```
</td></tr>
<tr><td>
```plain
BenchmarkFmtSprint-4 143 ns/op 2 allocs/op
```
</td><td>
```plain
BenchmarkStrconv-4 64.2 ns/op 1 allocs/op
```
</td></tr>
</tbody></table>