xref: /aosp_15_r20/external/licenseclassifier/internal/sets/sets_benchmark_test.go (revision 46c4c49da23cae783fa41bf46525a6505638499a)
1// Copyright 2017 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//	http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package sets
15
16import (
17	"strings"
18	"testing"
19)
20
21const (
22	postmodernThesisCollapse = `1. Expressions of collapse
23
24If one examines postcultural Marxism, one is faced with a choice: either
25reject capitalist submodern theory or conclude that the purpose of the reader
26is significant form. Bataille uses the termcapitalist constructionto denote
27not, in fact, discourse, but prediscourse.
28
29Therefore, in Stardust, Gaiman analyses postcultural Marxism; in
30The Books of Magic, although, he denies capitalist submodern theory. If
31capitalist construction holds, we have to choose between capitalist submodern
32theory and Baudrillardist simulacra.
33
34However, conceptualist socialism implies that narrativity may be used to
35oppress the proletariat, given that sexuality is distinct from art. The subject
36is interpolated into a capitalist construction that includes language as a
37paradox.
38`
39	postmodernThesisNarratives = `1. Narratives of failure
40
41The main theme of the works of Joyce is the defining characteristic, and some
42would say the economy, of neocultural class. But Bataille promotes the use of
43socialist realism to deconstruct sexual identity.
44
45The subject is interpolated into a Baudrillardist simulation that includes
46consciousness as a whole. Thus, the primary theme of Pickett's[1] model of
47socialist realism is the role of the reader as artist.
48
49The subject is contextualised into a postcapitalist discourse that includes
50language as a paradox. It could be said that if Baudrillardist simulation
51holds, the works of Gibson are postmodern. The characteristic theme of the
52works of Gibson is the common ground between society and narrativity. However,
53Sartre uses the term 'postcapitalist discourse' to denote not, in fact,
54narrative, but postnarrative.
55`
56)
57
58var (
59	// Word lists:
60	stringsA = strings.Fields(postmodernThesisCollapse)
61	stringsB = strings.Fields(postmodernThesisNarratives)
62)
63
64func BenchmarkStringSets_NewStringSet(b *testing.B) {
65	b.ResetTimer()
66	for i := 0; i < b.N; i++ {
67		NewStringSet(stringsA...)
68	}
69}
70
71func BenchmarkStringSets_Copy(b *testing.B) {
72	s := NewStringSet(stringsA...)
73
74	b.ResetTimer()
75	for i := 0; i < b.N; i++ {
76		s.Copy()
77	}
78}
79
80func BenchmarkStringSets_Insert(b *testing.B) {
81	b.ResetTimer()
82	for i := 0; i < b.N; i++ {
83		s := NewStringSet()
84		s.Insert(stringsA...)
85		s.Insert(stringsB...)
86	}
87}
88
89func BenchmarkStringSets_Delete(b *testing.B) {
90	b.ResetTimer()
91	for i := 0; i < b.N; i++ {
92		s := NewStringSet(stringsA...)
93		s.Delete(stringsB...)
94	}
95}
96
97func BenchmarkStringSets_Intersect(b *testing.B) {
98	s := NewStringSet(stringsA...)
99	t := NewStringSet(stringsB...)
100
101	b.ResetTimer()
102	for i := 0; i < b.N; i++ {
103		s.Intersect(t)
104	}
105}
106
107func BenchmarkStringSets_Disjoint(b *testing.B) {
108	s := NewStringSet(stringsA...)
109	t := NewStringSet(stringsB...)
110
111	b.ResetTimer()
112	for i := 0; i < b.N; i++ {
113		s.Disjoint(t)
114	}
115}
116
117func BenchmarkStringSets_Difference(b *testing.B) {
118	s := NewStringSet(stringsA...)
119	t := NewStringSet(stringsB...)
120
121	b.ResetTimer()
122	for i := 0; i < b.N; i++ {
123		s.Difference(t)
124	}
125}
126
127func BenchmarkStringSets_Unique(b *testing.B) {
128	s := NewStringSet(stringsA...)
129	t := NewStringSet(stringsB...)
130
131	b.ResetTimer()
132	for i := 0; i < b.N; i++ {
133		s.Unique(t)
134	}
135}
136
137func BenchmarkStringSets_Equal(b *testing.B) {
138	s := NewStringSet(stringsA...)
139	t := NewStringSet(stringsB...)
140
141	b.ResetTimer()
142	for i := 0; i < b.N; i++ {
143		s.Equal(t)
144	}
145}
146
147func BenchmarkStringSets_Union(b *testing.B) {
148	s := NewStringSet(stringsA...)
149	t := NewStringSet(stringsB...)
150
151	b.ResetTimer()
152	for i := 0; i < b.N; i++ {
153		s.Union(t)
154	}
155}
156
157func BenchmarkStringSets_Contains(b *testing.B) {
158	s := NewStringSet(stringsA...)
159
160	b.ResetTimer()
161	for i := 0; i < b.N; i++ {
162		for _, w := range stringsB {
163			s.Contains(w)
164		}
165	}
166}
167
168func BenchmarkStringSets_Len(b *testing.B) {
169	s := NewStringSet(stringsA...)
170
171	b.ResetTimer()
172	for i := 0; i < b.N; i++ {
173		s.Len()
174	}
175}
176
177func BenchmarkStringSets_Empty(b *testing.B) {
178	s := NewStringSet(stringsA...)
179	t := NewStringSet()
180
181	b.ResetTimer()
182	for i := 0; i < b.N; i++ {
183		s.Empty()
184		t.Empty()
185	}
186}
187
188func BenchmarkStringSets_Elements(b *testing.B) {
189	s := NewStringSet(stringsA...)
190
191	b.ResetTimer()
192	for i := 0; i < b.N; i++ {
193		s.Elements()
194	}
195}
196
197func BenchmarkStringSets_Sorted(b *testing.B) {
198	s := NewStringSet(stringsA...)
199
200	b.ResetTimer()
201	for i := 0; i < b.N; i++ {
202		s.Sorted()
203	}
204}
205
206func BenchmarkStringSets_String(b *testing.B) {
207	s := NewStringSet(stringsA...)
208
209	b.ResetTimer()
210	for i := 0; i < b.N; i++ {
211		s.String()
212	}
213}
214