Rebase.
[official-gcc.git] / libgo / go / runtime / string_test.go
blobdf3ff06a7dd812bc2b1e6554520688833ea863e4
1 // Copyright 2012 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.
5 package runtime_test
7 import (
8 "testing"
11 func BenchmarkCompareStringEqual(b *testing.B) {
12 bytes := []byte("Hello Gophers!")
13 s1, s2 := string(bytes), string(bytes)
14 for i := 0; i < b.N; i++ {
15 if s1 != s2 {
16 b.Fatal("s1 != s2")
21 func BenchmarkCompareStringIdentical(b *testing.B) {
22 s1 := "Hello Gophers!"
23 s2 := s1
24 for i := 0; i < b.N; i++ {
25 if s1 != s2 {
26 b.Fatal("s1 != s2")
31 func BenchmarkCompareStringSameLength(b *testing.B) {
32 s1 := "Hello Gophers!"
33 s2 := "Hello, Gophers"
34 for i := 0; i < b.N; i++ {
35 if s1 == s2 {
36 b.Fatal("s1 == s2")
41 func BenchmarkCompareStringDifferentLength(b *testing.B) {
42 s1 := "Hello Gophers!"
43 s2 := "Hello, Gophers!"
44 for i := 0; i < b.N; i++ {
45 if s1 == s2 {
46 b.Fatal("s1 == s2")
51 func BenchmarkCompareStringBigUnaligned(b *testing.B) {
52 bytes := make([]byte, 0, 1<<20)
53 for len(bytes) < 1<<20 {
54 bytes = append(bytes, "Hello Gophers!"...)
56 s1, s2 := string(bytes), "hello"+string(bytes)
57 for i := 0; i < b.N; i++ {
58 if s1 != s2[len("hello"):] {
59 b.Fatal("s1 != s2")
62 b.SetBytes(int64(len(s1)))
65 func BenchmarkCompareStringBig(b *testing.B) {
66 bytes := make([]byte, 0, 1<<20)
67 for len(bytes) < 1<<20 {
68 bytes = append(bytes, "Hello Gophers!"...)
70 s1, s2 := string(bytes), string(bytes)
71 for i := 0; i < b.N; i++ {
72 if s1 != s2 {
73 b.Fatal("s1 != s2")
76 b.SetBytes(int64(len(s1)))