// 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
10 Best Exercises To Do At Home
30ngày30 ngày
30bước30 bước
Tất cả những ai đã hoàn thành tất cả các bước sẽ nhận được huy hiệu khi chương trình kết thúc.
Giới thiệu
A regular workout is the best way to live a fit and healthy life. For the days you can't hit the gym, check out these 10 full-body exercises to do at home with little to no equipment
Bạn cũng có thể tham gia chương trình này thông qua ứng dụng di động. Truy cập ứng dụng