...

Source file src/golang.org/x/text/secure/bidirule/bench_test.go

Documentation: golang.org/x/text/secure/bidirule

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package bidirule
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  var benchData = []struct{ name, data string }{
    12  	{"ascii", "Scheveningen"},
    13  	{"arabic", "دبي"},
    14  	{"hangul", "다음과"},
    15  }
    16  
    17  func doBench(b *testing.B, fn func(b *testing.B, data string)) {
    18  	for _, d := range benchData {
    19  		b.Run(d.name, func(b *testing.B) { fn(b, d.data) })
    20  	}
    21  }
    22  
    23  func BenchmarkSpan(b *testing.B) {
    24  	r := New()
    25  	doBench(b, func(b *testing.B, str string) {
    26  		b.SetBytes(int64(len(str)))
    27  		data := []byte(str)
    28  		for i := 0; i < b.N; i++ {
    29  			r.Reset()
    30  			r.Span(data, true)
    31  		}
    32  	})
    33  }
    34  
    35  func BenchmarkDirectionASCII(b *testing.B) {
    36  	doBench(b, func(b *testing.B, str string) {
    37  		b.SetBytes(int64(len(str)))
    38  		data := []byte(str)
    39  		for i := 0; i < b.N; i++ {
    40  			Direction(data)
    41  		}
    42  	})
    43  }
    44  
    45  func BenchmarkDirectionStringASCII(b *testing.B) {
    46  	doBench(b, func(b *testing.B, str string) {
    47  		b.SetBytes(int64(len(str)))
    48  		for i := 0; i < b.N; i++ {
    49  			DirectionString(str)
    50  		}
    51  	})
    52  }
    53  

View as plain text