[cost] add objc test for NSDictionary and NSMutableDictionary

Summary:
Add test for ```NSDictionary``` and ```NSMutableDictionary```.
```NSMutableDictionary``` is a subclass of ```NSDictionary```.

[Doc]
```NSDictionary```
https://developer.apple.com/documentation/foundation/nsdictionary?language=objc

```NSMutableDictionary```
https://developer.apple.com/documentation/foundation/nsmutabledictionary?language=objc

Reviewed By: skcho

Differential Revision: D22041942

fbshipit-source-id: d1a1aa781
master
Qianyi Shu 5 years ago committed by Facebook GitHub Bot
parent 6e37247b7b
commit 9e0d5de91d

@ -0,0 +1,62 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
// init dictionary
NSDictionary* nsdictionary_init_literal_constant() {
NSDictionary* dict =
@{@"helloString" : @"Hello, World!",
@"magicNumber" : @42};
return dict;
}
NSDictionary* nsdictionary_init_dictionary_constant() {
return [NSDictionary dictionary];
}
void nsdictionary_init_with_dictionary_linear_FP(NSDictionary* dict) {
NSDictionary* copy_dict = [[NSDictionary alloc] initWithDictionary:dict];
for (int i = 0; i < [copy_dict allValues].count; i++) {
}
}
// accessing values and keys
void nsdictionary_all_keys_linear_FP(NSDictionary* dict) {
for (int i = 0; i < [dict allKeys].count; i++) {
}
}
void nsdictionary_all_values_linear_FP(NSDictionary* dict) {
for (int i = 0; i < [dict allValues].count; i++) {
}
}
// enumerate dictionary
void nsdictionary_fast_enumerate_linear_FN(NSDictionary* dict) {
for (id key in dict) {
}
}
void nsdictionary_enumerate_constant() {
NSDictionary* dict =
@{@"helloString" : @"Hello, World!",
@"magicNumber" : @42};
for (NSString* key in dict) {
id value = dict[key];
}
}
void nsdictionary_enumerator_linear_FN(NSDictionary* dict) {
NSEnumerator* enumerator = [dict keyEnumerator];
id key;
while ((key = [enumerator nextObject])) {
}
}

@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
// set element
void nsmutabledictionary_set_element_in_loop_linear_FN(
NSMutableDictionary* dict) {
for (NSString* key in dict) {
dict[key] = key;
}
}

@ -17,6 +17,14 @@ codetoanalyze/objc/performance/NSArray.m, nsarray_last_object_constant, 4, OnUI
codetoanalyze/objc/performance/NSArray.m, nsarray_sort_using_descriptors_constant, 14, OnUIThread:false, []
codetoanalyze/objc/performance/NSArray.m, nsarray_sort_using_descriptors_nlogn_FN, 9, OnUIThread:false, []
codetoanalyze/objc/performance/NSArray.m, objc_blocknsarray_binary_search_log_FN_1, 5, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_keys_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 31, column 3]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_values_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 36, column 3]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerate_constant, 20, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_enumerator_linear_FN, 10, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_fast_enumerate_linear_FN, 10, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_dictionary_constant, 3, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_literal_constant, 9, OnUIThread:false, []
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 24, column 3]
codetoanalyze/objc/performance/NSInteger.m, nsinteger_value_linear, 3 + 3 ⋅ integer + 2 ⋅ (1+max(0, integer)), OnUIThread:false, [{1+max(0, integer)},Loop at line 10, column 3,{integer},Loop at line 10, column 3]
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_add_all_constant, 25, OnUIThread:false, []
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_add_in_loop_constant_FP, , OnUIThread:false, [Unbounded loop,Loop at line 31, column 3]
@ -30,6 +38,7 @@ codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_reomove_constant, 15,
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_set_constant, 4, OnUIThread:false, []
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_set_constant_FP, , OnUIThread:false, [Unbounded loop,Loop at line 101, column 3]
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_set_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 90, column 3]
codetoanalyze/objc/performance/NSMutableDictionary.m, nsmutabledictionary_set_element_in_loop_linear_FN, 14, OnUIThread:false, []
codetoanalyze/objc/performance/NSString.m, call_component_separated_by_string_constant_FP, , OnUIThread:false, [Call to component_seperated_by_string_linear_FP,Unbounded loop,Loop at line 42, column 3]
codetoanalyze/objc/performance/NSString.m, call_init_with_string_constant_FP, , OnUIThread:false, [Call to init_with_string_linear_FP,Unbounded loop,Loop at line 70, column 3]
codetoanalyze/objc/performance/NSString.m, component_seperated_by_string_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 42, column 3]

@ -9,6 +9,12 @@ codetoanalyze/objc/performance/NSArray.m, nsarray_init_with_array_copy_linear_FP
codetoanalyze/objc/performance/NSArray.m, nsarray_init_with_array_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 21, column 3]
codetoanalyze/objc/performance/NSArray.m, nsarray_init_with_array_linear_FP, 3, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSArray.count,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSArray.m, nsarray_iterate_linear_FN, 3, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Assignment,<RHS trace>,Unknown value from: NSArray.nextObject,Assignment,Binary operation: ([-oo, +oo] + [-oo, +oo]):signed64]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_keys_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 31, column 3]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_keys_linear_FP, 1, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSArray.count,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_values_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 36, column 3]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_all_values_linear_FP, 1, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSArray.count,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 24, column 3]
codetoanalyze/objc/performance/NSDictionary.m, nsdictionary_init_with_dictionary_linear_FP, 2, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSArray.count,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_add_in_loop_constant_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 31, column 3]
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_add_in_loop_constant_FP, 5, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSArray.count,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSMutableArray.m, nsmarray_add_then_loop_constant_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 67, column 3]

Loading…
Cancel
Save