benchmarks_test.go 407 B

1234567891011121314151617181920212223242526
  1. package ut
  2. import "testing"
  3. func BenchmarkBasicTranslation(b *testing.B) {
  4. ut, _ := New("en", "en")
  5. loc := ut.FindTranslator("en")
  6. loc.Add("welcome", "Welcome to the site")
  7. b.Run("", func(b *testing.B) {
  8. for i := 0; i < b.N; i++ {
  9. loc.T("welcome")
  10. }
  11. })
  12. b.Run("Parallel", func(b *testing.B) {
  13. b.RunParallel(func(pb *testing.PB) {
  14. for pb.Next() {
  15. loc.T("welcome")
  16. }
  17. })
  18. })
  19. }