// Sample benchmarks to test which function is better for converting
// an integer into a string. First using the fmt.Sprintf function,
// then the strconv.FormatInt function and then strconv.Itoa.
package listing05_test
import (
"fmt"
"strconv"
"testing"
)
// BenchmarkSprintf provides performance numbers for the
// fmt.Sprintf function.
func BenchmarkSprintf(b *testing.B) {
number := 10
b.ResetTimer()
for i := 0; i < b.N; i++ {
fmt.Sprintf("%d", number)
}
}
// BenchmarkFormat provides performance numbers for the
// strconv.FormatInt function.
func BenchmarkFormat(b *testing.B) {
number := int64(10)
b.ResetTimer()
for i := 0; i < b.N; i++ {
strconv.FormatInt(number, 10)
}
}
// BenchmarkItoa provides performance numbers for the
// strconv.Itoa function.
func BenchmarkItoa(b *testing.B) {
number := 10
b.ResetTimer()
for i := 0; i < b.N; i++ {
strconv.Itoa(number)
}
}
$w
top of page
Dress To Impress
Fruits & Veggies 🍎🥕
30Araw30 Araw
30Hakbang30 Hakbang
Tatanggap ng badge ang lahat ng nakatapos ng program kapag natapos ang program.
Tungkol Dito
Doctors recommend getting at least five portions of fruits and veggies into your diet every day.
Easier said than done, but no worries! Get the encouragement you need to keep your health on track, plus some ideas for healthy alternatives.
Puwede ka ring sumali sa program na ito sa pamamagitan ng mobile app. Pumunta sa app