~samwhited/xmpp

ref: b2f3a9a952493ffcf467eafa59803c27fa099e2d xmpp/jid/benchmark_test.go -rw-r--r-- 2.9 KiB
b2f3a9a9Sam Whited xmpp: make SendElement safe for concurrent use 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2014 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

package jid

import (
	"testing"
)

func BenchmarkSplit(b *testing.B) {
	for i := 0; i < b.N; i++ {
		SplitString("user@example.com/resource")
	}
}

func BenchmarkParseString(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = Parse("user@example.com/resource")
	}
}

func BenchmarkParseStringIPv4(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = Parse("user@127.0.0.1/resource")
	}
}

func BenchmarkParseStringIPv6(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = Parse("user@[::1]/resource")
	}
}

func BenchmarkParseUnsafeString(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = ParseUnsafe("user@example.com/resource")
	}
}

func BenchmarkParseUnsafeStringIPv4(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = ParseUnsafe("user@127.0.0.1/resource")
	}
}

func BenchmarkParseUnsafeStringIPv6(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = ParseUnsafe("user@[::1]/resource")
	}
}

func BenchmarkNewFull(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = New("user", "example.com", "resource")
	}
}

func BenchmarkNewBare(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = New("user", "example.com", "")
	}
}

func BenchmarkNewDomain(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, _ = New("", "example.com", "")
	}
}

func BenchmarkWithLocal(b *testing.B) {
	j := MustParse("local@example.com")
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, _ = j.WithResource("local")
	}
}

func BenchmarkWithDomain(b *testing.B) {
	j := MustParse("local@example.com")
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, _ = j.WithDomain("example.org")
	}
}

func BenchmarkWithResource(b *testing.B) {
	j := MustParse("example.com/res")
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, _ = j.WithResource("res")
	}
}

func BenchmarkCopy(b *testing.B) {
	j := JID{4, 11, []byte("userexample.comresource")}
	for i := 0; i < b.N; i++ {
		_ = j.Copy()
	}
}

func BenchmarkBare(b *testing.B) {
	j := JID{4, 11, []byte("userexample.comresource")}
	for i := 0; i < b.N; i++ {
		_ = j.Bare()
	}
}

func BenchmarkString(b *testing.B) {
	j := JID{4, 11, []byte("userexample.comresource")}
	for i := 0; i < b.N; i++ {
		_ = j.String()
	}
}

func BenchmarkEscapeTransform(b *testing.B) {
	src := []byte(escape)
	dst := make([]byte, len(src)+18)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		Escape.Transform(dst, src, true)
	}
}

func BenchmarkUnescapeTransform(b *testing.B) {
	src := []byte(allescaped)
	dst := make([]byte, len(src)/3)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		Unescape.Transform(dst, src, true)
	}
}

func BenchmarkEscapeBytes(b *testing.B) {
	src := []byte(escape)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = Escape.Bytes(src)
	}
}

func BenchmarkUnescapeBytes(b *testing.B) {
	src := []byte(allescaped)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = Unescape.Bytes(src)
	}
}