• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Protocol Buffers - Google's data interchange format
2// Copyright 2013 Google Inc.  All rights reserved.
3// https://developers.google.com/protocol-buffers/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9//     * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11//     * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15//     * Neither the name of Google Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31#import "GPBTestUtilities.h"
32#import "google/protobuf/Unittest.pbobjc.h"
33#import "google/protobuf/UnittestImport.pbobjc.h"
34#import "google/protobuf/UnittestObjc.pbobjc.h"
35
36//
37// This file really just uses the unittests framework as a testbed to
38// run some simple performance tests. The data can then be used to help
39// evaluate changes to the runtime.
40//
41
42static const uint32_t kRepeatedCount = 100;
43
44@interface PerfTests : GPBTestCase
45@end
46
47@implementation PerfTests
48
49- (void)setUp {
50  // A convenient place to put a break point if you want to connect instruments.
51  [super setUp];
52}
53
54- (void)testMessagePerformance {
55  [self measureBlock:^{
56    for (int i = 0; i < 200; ++i) {
57      TestAllTypes* message = [[TestAllTypes alloc] init];
58      [self setAllFields:message repeatedCount:kRepeatedCount];
59      NSData* rawBytes = [message data];
60      [message release];
61      message = [[TestAllTypes alloc] initWithData:rawBytes error:NULL];
62      [message release];
63    }
64  }];
65}
66
67- (void)testExtensionsPerformance {
68  [self measureBlock:^{
69    for (int i = 0; i < 200; ++i) {
70      TestAllExtensions* message = [[TestAllExtensions alloc] init];
71      [self setAllExtensions:message repeatedCount:kRepeatedCount];
72      NSData* rawBytes = [message data];
73      [message release];
74      TestAllExtensions* message2 =
75          [[TestAllExtensions alloc] initWithData:rawBytes error:NULL];
76      [message2 release];
77    }
78  }];
79}
80
81- (void)testPackedTypesPerformance {
82  [self measureBlock:^{
83    for (int i = 0; i < 1000; ++i) {
84      TestPackedTypes* message = [[TestPackedTypes alloc] init];
85      [self setPackedFields:message repeatedCount:kRepeatedCount];
86      NSData* rawBytes = [message data];
87      [message release];
88      message = [[TestPackedTypes alloc] initWithData:rawBytes error:NULL];
89      [message release];
90    }
91  }];
92}
93
94- (void)testPackedExtensionsPerformance {
95  [self measureBlock:^{
96    for (int i = 0; i < 1000; ++i) {
97      TestPackedExtensions* message = [[TestPackedExtensions alloc] init];
98      [self setPackedExtensions:message repeatedCount:kRepeatedCount];
99      NSData* rawBytes = [message data];
100      [message release];
101      TestPackedExtensions* message2 =
102          [[TestPackedExtensions alloc] initWithData:rawBytes error:NULL];
103      [message2 release];
104    }
105  }];
106}
107
108- (void)testHas {
109  TestAllTypes* message = [self allSetRepeatedCount:1];
110  [self measureBlock:^{
111    for (int i = 0; i < 10000; ++i) {
112      [message hasOptionalInt32];
113      message.hasOptionalInt32 = NO;
114      [message hasOptionalInt32];
115
116      [message hasOptionalInt64];
117      message.hasOptionalInt64 = NO;
118      [message hasOptionalInt64];
119
120      [message hasOptionalUint32];
121      message.hasOptionalUint32 = NO;
122      [message hasOptionalUint32];
123
124      [message hasOptionalUint64];
125      message.hasOptionalUint64 = NO;
126      [message hasOptionalUint64];
127
128      [message hasOptionalSint32];
129      message.hasOptionalSint32 = NO;
130      [message hasOptionalSint32];
131
132      [message hasOptionalSint64];
133      message.hasOptionalSint64 = NO;
134      [message hasOptionalSint64];
135
136      [message hasOptionalFixed32];
137      message.hasOptionalFixed32 = NO;
138      [message hasOptionalFixed32];
139
140      [message hasOptionalFixed64];
141      message.hasOptionalFixed64 = NO;
142      [message hasOptionalFixed64];
143
144      [message hasOptionalSfixed32];
145      message.hasOptionalSfixed32 = NO;
146      [message hasOptionalSfixed32];
147
148      [message hasOptionalSfixed64];
149      message.hasOptionalSfixed64 = NO;
150      [message hasOptionalSfixed64];
151
152      [message hasOptionalFloat];
153      message.hasOptionalFloat = NO;
154      [message hasOptionalFloat];
155
156      [message hasOptionalDouble];
157      message.hasOptionalDouble = NO;
158      [message hasOptionalDouble];
159
160      [message hasOptionalBool];
161      message.hasOptionalBool = NO;
162      [message hasOptionalBool];
163
164      [message hasOptionalString];
165      message.hasOptionalString = NO;
166      [message hasOptionalString];
167
168      [message hasOptionalBytes];
169      message.hasOptionalBytes = NO;
170      [message hasOptionalBytes];
171
172      [message hasOptionalGroup];
173      message.hasOptionalGroup = NO;
174      [message hasOptionalGroup];
175
176      [message hasOptionalNestedMessage];
177      message.hasOptionalNestedMessage = NO;
178      [message hasOptionalNestedMessage];
179
180      [message hasOptionalForeignMessage];
181      message.hasOptionalForeignMessage = NO;
182      [message hasOptionalForeignMessage];
183
184      [message hasOptionalImportMessage];
185      message.hasOptionalImportMessage = NO;
186      [message hasOptionalImportMessage];
187
188      [message.optionalGroup hasA];
189      message.optionalGroup.hasA = NO;
190      [message.optionalGroup hasA];
191
192      [message.optionalNestedMessage hasBb];
193      message.optionalNestedMessage.hasBb = NO;
194      [message.optionalNestedMessage hasBb];
195
196      [message.optionalForeignMessage hasC];
197      message.optionalForeignMessage.hasC = NO;
198      [message.optionalForeignMessage hasC];
199
200      [message.optionalImportMessage hasD];
201      message.optionalImportMessage.hasD = NO;
202      [message.optionalImportMessage hasD];
203
204      [message hasOptionalNestedEnum];
205      message.hasOptionalNestedEnum = NO;
206      [message hasOptionalNestedEnum];
207
208      [message hasOptionalForeignEnum];
209      message.hasOptionalForeignEnum = NO;
210      [message hasOptionalForeignEnum];
211
212      [message hasOptionalImportEnum];
213      message.hasOptionalImportEnum = NO;
214      [message hasOptionalImportEnum];
215
216      [message hasOptionalStringPiece];
217      message.hasOptionalStringPiece = NO;
218      [message hasOptionalStringPiece];
219
220      [message hasOptionalCord];
221      message.hasOptionalCord = NO;
222      [message hasOptionalCord];
223
224      [message hasDefaultInt32];
225      message.hasDefaultInt32 = NO;
226      [message hasDefaultInt32];
227
228      [message hasDefaultInt64];
229      message.hasDefaultInt64 = NO;
230      [message hasDefaultInt64];
231
232      [message hasDefaultUint32];
233      message.hasDefaultUint32 = NO;
234      [message hasDefaultUint32];
235
236      [message hasDefaultUint64];
237      message.hasDefaultUint64 = NO;
238      [message hasDefaultUint64];
239
240      [message hasDefaultSint32];
241      message.hasDefaultSint32 = NO;
242      [message hasDefaultSint32];
243
244      [message hasDefaultSint64];
245      message.hasDefaultSint64 = NO;
246      [message hasDefaultSint64];
247
248      [message hasDefaultFixed32];
249      message.hasDefaultFixed32 = NO;
250      [message hasDefaultFixed32];
251
252      [message hasDefaultFixed64];
253      message.hasDefaultFixed64 = NO;
254      [message hasDefaultFixed64];
255
256      [message hasDefaultSfixed32];
257      message.hasDefaultSfixed32 = NO;
258      [message hasDefaultSfixed32];
259
260      [message hasDefaultSfixed64];
261      message.hasDefaultSfixed64 = NO;
262      [message hasDefaultSfixed64];
263
264      [message hasDefaultFloat];
265      message.hasDefaultFloat = NO;
266      [message hasDefaultFloat];
267
268      [message hasDefaultDouble];
269      message.hasDefaultDouble = NO;
270      [message hasDefaultDouble];
271
272      [message hasDefaultBool];
273      message.hasDefaultBool = NO;
274      [message hasDefaultBool];
275
276      [message hasDefaultString];
277      message.hasDefaultString = NO;
278      [message hasDefaultString];
279
280      [message hasDefaultBytes];
281      message.hasDefaultBytes = NO;
282      [message hasDefaultBytes];
283
284      [message hasDefaultNestedEnum];
285      message.hasDefaultNestedEnum = NO;
286      [message hasDefaultNestedEnum];
287
288      [message hasDefaultForeignEnum];
289      message.hasDefaultForeignEnum = NO;
290      [message hasDefaultForeignEnum];
291
292      [message hasDefaultImportEnum];
293      message.hasDefaultImportEnum = NO;
294      [message hasDefaultImportEnum];
295
296      [message hasDefaultStringPiece];
297      message.hasDefaultStringPiece = NO;
298      [message hasDefaultStringPiece];
299
300      [message hasDefaultCord];
301      message.hasDefaultCord = NO;
302      [message hasDefaultCord];
303    }
304  }];
305}
306
307@end
308