123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package ut
- import "testing"
- func BenchmarkBasicTranslation(b *testing.B) {
- ut, _ := New("en", "en")
- loc := ut.FindTranslator("en")
- loc.Add("welcome", "Welcome to the site")
- loc.Add("welcome-user", "Welcome to the site {0}")
- loc.Add("welcome-user2", "Welcome to the site {0}, your location is {1}")
- b.Run("", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- loc.T("welcome")
- }
- })
- b.Run("Parallel", func(b *testing.B) {
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- loc.T("welcome")
- }
- })
- })
- b.Run("With1Param", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- loc.T("welcome-user", "Joeybloggs")
- }
- })
- b.Run("ParallelWith1Param", func(b *testing.B) {
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- loc.T("welcome-user", "Joeybloggs")
- }
- })
- })
- b.Run("With2Param", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- loc.T("welcome-user2", "Joeybloggs", "/dev/tty0")
- }
- })
- b.Run("ParallelWith2Param", func(b *testing.B) {
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- loc.T("welcome-user2", "Joeybloggs", "/dev/tty0")
- }
- })
- })
- }
|