// 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
30-Day Get Moving Challenge
30Ημέρες30 Ημέρες
30Βήματα30 Βήματα
Όλοι όσοι έχουν ολοκληρώσει όλα τα βήματα θα λάβουν μια κονκάρδα όταν τελειώσει το πρόγραμμα.
Σχετικά με
Moving your body is one of the best ways to improve your mood and your health, and that’s what this challenge is all about. No magic. No wizardry. Just 30 days of exercises built for any time and any location, no equipment needed. Watch the videos, and let's get moving
Μπορείτε επίσης να συμμετάσχετε σε αυτό το πρόγραμμα μέσω της εφαρμογής για κινητά. Μεταβείτε στην εφαρμογή