[cost] add objc test case for NSInteger and NSString

Summary:
Add objc test case for ```NSInteger``` and ```NSString```.
The test cases are adapted from java test case: ```IntTest.java```, ```StringBuilder.java```, and  ```StringTest.java```.

Inspection of the record will be done later.

Reviewed By: ezgicicek

Differential Revision: D21994620

fbshipit-source-id: 0c1d7b34e
master
Qianyi Shu 5 years ago committed by Facebook GitHub Bot
parent 412d2777eb
commit cb805882c2

@ -0,0 +1,12 @@
/*
* 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>
void nsinteger_value_linear(NSInteger integer) {
for (int count = 0; count < integer; count++) {
}
}

@ -0,0 +1,89 @@
/*
* 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>
NSString* mId;
NSCharacterSet* characterSet;
NSString* string_by_appending_same_string_linear_FN(NSString* s) {
NSString* str = [s stringByAppendingString:@"me"];
return str;
}
NSString* string_by_appending_string_linear_FN(NSString* s, NSString* m) {
NSString* str = [s stringByAppendingString:m];
return str;
}
NSUInteger rangeof_character_from_set_linear_FN(NSString* m) {
return [m rangeOfString:@"_"].location;
}
NSUInteger rangeof_string_quadratic_FN(NSString* m, NSString* n) {
return [m rangeOfString:n].location;
}
NSString* substring_from_index_linear_FN() {
NSUInteger index = rangeof_character_from_set_linear_FN(mId);
return [mId substringToIndex:index];
}
NSString* has_prefix_constant() {
NSString* s = @"";
return [s hasPrefix:s] ? [s substringFromIndex:1] : s;
}
void component_seperated_by_string_linear_FP(NSString* m) {
NSArray* arrayOfComponents = [m componentsSeparatedByString:@","];
for (int i = 0; i < arrayOfComponents.count; i++) {
}
}
void call_component_separated_by_string_constant_FP() {
NSString* s = @"hello";
component_seperated_by_string_linear_FP(s);
}
void init_with_bytes_linear_FP(const void* bytes,
NSUInteger length,
NSStringEncoding encoding) {
NSString* s = [[NSString alloc] initWithBytes:bytes
length:length
encoding:encoding];
for (int i = 0; i < s.length; i++) {
}
}
void init_with_string_constant_FP() {
NSString* s = @"abcd";
NSString* str = [[NSString alloc] initWithString:s];
for (int i = 0; i < str.length; i++) {
}
}
void init_with_string_linear_FP(NSString* s) {
NSString* str = [[NSString alloc] initWithString:s];
for (int i = 0; i < str.length; i++) {
}
}
void call_init_with_string_constant_FP() {
NSString* s = [[NSString alloc] init];
init_with_string_linear_FP(s);
}
void substring_no_end_linear_FP(NSString* s, int x) {
NSString* sub = [s substringFromIndex:x];
for (int i = 0; i < sub.length; i++) {
}
}
void replace_linear_FP(NSString* s) {
NSString* r = [s stringByReplacingOccurrencesOfString:@"." withString:@","];
for (int i = 0; i < r.length; i++) {
}
}

@ -1,3 +1,18 @@
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/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]
codetoanalyze/objc/performance/NSString.m, has_prefix_constant, 15, OnUIThread:false, []
codetoanalyze/objc/performance/NSString.m, init_with_bytes_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 57, column 3]
codetoanalyze/objc/performance/NSString.m, init_with_string_constant_FP, , OnUIThread:false, [Unbounded loop,Loop at line 64, column 3]
codetoanalyze/objc/performance/NSString.m, init_with_string_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 70, column 3]
codetoanalyze/objc/performance/NSString.m, rangeof_character_from_set_linear_FN, 6, OnUIThread:false, []
codetoanalyze/objc/performance/NSString.m, rangeof_string_quadratic_FN, 6, OnUIThread:false, []
codetoanalyze/objc/performance/NSString.m, replace_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 87, column 3]
codetoanalyze/objc/performance/NSString.m, string_by_appending_same_string_linear_FN, 7, OnUIThread:false, []
codetoanalyze/objc/performance/NSString.m, string_by_appending_string_linear_FN, 7, OnUIThread:false, []
codetoanalyze/objc/performance/NSString.m, substring_from_index_linear_FN, 13, OnUIThread:false, []
codetoanalyze/objc/performance/NSString.m, substring_no_end_linear_FP, , OnUIThread:false, [Unbounded loop,Loop at line 81, column 3]
codetoanalyze/objc/performance/araii.m, Araii.dealloc, 4, OnUIThread:false, []
codetoanalyze/objc/performance/araii.m, Araii.initWithBuffer, 15, OnUIThread:false, []
codetoanalyze/objc/performance/araii.m, memory_leak_raii_main, 18, OnUIThread:false, []

@ -1,3 +1,17 @@
codetoanalyze/objc/performance/NSString.m, call_component_separated_by_string_constant_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [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, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [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, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 42, column 3]
codetoanalyze/objc/performance/NSString.m, component_seperated_by_string_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/NSString.m, init_with_bytes_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 57, column 3]
codetoanalyze/objc/performance/NSString.m, init_with_bytes_linear_FP, 6, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSString.length,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSString.m, init_with_string_constant_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 64, column 3]
codetoanalyze/objc/performance/NSString.m, init_with_string_constant_FP, 3, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSString.length,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSString.m, init_with_string_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 70, column 3]
codetoanalyze/objc/performance/NSString.m, init_with_string_linear_FP, 2, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSString.length,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSString.m, replace_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 87, column 3]
codetoanalyze/objc/performance/NSString.m, replace_linear_FP, 2, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSString.length,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/NSString.m, substring_no_end_linear_FP, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 81, column 3]
codetoanalyze/objc/performance/NSString.m, substring_no_end_linear_FP, 2, INTEGER_OVERFLOW_U5, no_bucket, ERROR, [<LHS trace>,Unknown value from: NSString.length,Binary operation: ([0, +oo] + 1):signed32]
codetoanalyze/objc/performance/compound_loop_guard.m, compound_while, 3, CONDITION_ALWAYS_TRUE, no_bucket, WARNING, [Here]
codetoanalyze/objc/performance/compound_loop_guard.m, nested_while_and_or_constant, 3, CONDITION_ALWAYS_TRUE, no_bucket, WARNING, [Here]
codetoanalyze/objc/performance/compound_loop_guard.m, nested_while_and_or_constant, 3, CONDITION_ALWAYS_TRUE, no_bucket, WARNING, [Here]

Loading…
Cancel
Save