Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Updating XCTest for performance measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
vilanovi committed Nov 5, 2014
1 parent 8a34e4d commit 26a47e4
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 188 deletions.
75 changes: 75 additions & 0 deletions SampleProject/Motis Tests/MJPerformanceTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// MJPerformanceTest.m
// Motis
//
// Created by Joan Martin on 05/11/14.
// Copyright (c) 2014 Mobile Jazz. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#import "Motis.h"
#import "MJParser.h"

NSString *urlEncoding(NSString* string)
{
return (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)string, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);
}

NSString* uniqueString()
{
CFUUIDRef uuidObj = CFUUIDCreate(nil);
NSString *uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(nil, uuidObj);
CFRelease(uuidObj);
return uuidString;
}

@interface MJPerformanceTest : XCTestCase

@end

@implementation MJPerformanceTest
{
NSDictionary *_jsonDictionary;
}

- (void)setUp
{
[super setUp];

static NSData *data = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *file = @"data_25MB.json";
NSString *path = [[NSBundle bundleForClass:self.class] pathForResource:[file stringByDeletingPathExtension] ofType:[file pathExtension]];
data = [NSData dataWithContentsOfFile:path];
});

NSError *error = nil;
_jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
}

- (void)tearDown
{
_jsonDictionary = nil;
[super tearDown];
}

- (void)testPerformanceMotis
{
MJCountry *country = [[MJCountry alloc] init];
[self measureBlock:^{
[country mts_setValuesForKeysWithDictionary:_jsonDictionary];
}];
}

- (void)testPerformanceParser
{
[self measureBlock:^{
MJCountry *country = nil;
country = [MJParser parseCountry:_jsonDictionary];
}];
}

@end
94 changes: 46 additions & 48 deletions SampleProject/Motis.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
D2A0544618D8A5B80050DE68 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2C3463A18959EF2005B6B5C /* UIKit.framework */; };
D2A0544C18D8A5B80050DE68 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D2A0544A18D8A5B80050DE68 /* InfoPlist.strings */; };
D2A0544E18D8A5B80050DE68 /* MJValidationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A0544D18D8A5B80050DE68 /* MJValidationTest.m */; };
D2B776D2191B959500CC9B4F /* MJCompany.m in Sources */ = {isa = PBXBuildFile; fileRef = D2B776C8191B959500CC9B4F /* MJCompany.m */; };
D2B776D3191B959500CC9B4F /* MJCountry.m in Sources */ = {isa = PBXBuildFile; fileRef = D2B776CA191B959500CC9B4F /* MJCountry.m */; };
D2B776D4191B959500CC9B4F /* MJParser.m in Sources */ = {isa = PBXBuildFile; fileRef = D2B776CC191B959500CC9B4F /* MJParser.m */; };
D2B776D5191B959500CC9B4F /* MJPerson.m in Sources */ = {isa = PBXBuildFile; fileRef = D2B776CE191B959500CC9B4F /* MJPerson.m */; };
D2B776D6191B959500CC9B4F /* MJProject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2B776D0191B959500CC9B4F /* MJProject.m */; };
D2B776D7191B959500CC9B4F /* data_25MB.json in Resources */ = {isa = PBXBuildFile; fileRef = D2B776D1191B959500CC9B4F /* data_25MB.json */; };
D2B776DA191B95EA00CC9B4F /* MJPerformanceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D2B776D9191B95EA00CC9B4F /* MJPerformanceTest.m */; };
D2C3463718959EF2005B6B5C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2C3463618959EF2005B6B5C /* Foundation.framework */; };
D2C3463918959EF2005B6B5C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2C3463818959EF2005B6B5C /* CoreGraphics.framework */; };
D2C3463B18959EF2005B6B5C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2C3463A18959EF2005B6B5C /* UIKit.framework */; };
D2C890151A0ABBD700E81A9D /* MJPerformanceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C890141A0ABBD700E81A9D /* MJPerformanceTest.m */; };
D2C890221A0ABC2900E81A9D /* data_25MB.json in Resources */ = {isa = PBXBuildFile; fileRef = D2C890171A0ABC2900E81A9D /* data_25MB.json */; };
D2C890231A0ABC2900E81A9D /* MJCompany.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C890191A0ABC2900E81A9D /* MJCompany.m */; };
D2C890241A0ABC2900E81A9D /* MJCountry.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C8901B1A0ABC2900E81A9D /* MJCountry.m */; };
D2C890251A0ABC2900E81A9D /* MJParser.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C8901D1A0ABC2900E81A9D /* MJParser.m */; };
D2C890261A0ABC2900E81A9D /* MJPerson.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C8901F1A0ABC2900E81A9D /* MJPerson.m */; };
D2C890271A0ABC2900E81A9D /* MJProject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C890211A0ABC2900E81A9D /* MJProject.m */; };
D2DD9FD3192DF28400163C50 /* MJMotisObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2DD9FCC192DF28400163C50 /* MJMotisObject.m */; };
D2DD9FD4192DF28400163C50 /* MJMotisObjectNonRestricted.m in Sources */ = {isa = PBXBuildFile; fileRef = D2DD9FCE192DF28400163C50 /* MJMotisObjectNonRestricted.m */; };
D2DD9FD5192DF28400163C50 /* MJMotisObjectWithFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = D2DD9FD0192DF28400163C50 /* MJMotisObjectWithFormatter.m */; };
Expand Down Expand Up @@ -62,24 +62,23 @@
D2A0544D18D8A5B80050DE68 /* MJValidationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJValidationTest.m; sourceTree = "<group>"; };
D2A0544F18D8A5B80050DE68 /* Motis Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Motis Tests-Prefix.pch"; sourceTree = "<group>"; };
D2B776BF191B945400CC9B4F /* Motis copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Motis copy-Info.plist"; path = "/Users/martinhj/Documents/MobileJazz/repos/Motis/SampleProject/Motis copy-Info.plist"; sourceTree = "<absolute>"; };
D2B776C7191B959500CC9B4F /* MJCompany.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJCompany.h; sourceTree = "<group>"; };
D2B776C8191B959500CC9B4F /* MJCompany.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJCompany.m; sourceTree = "<group>"; };
D2B776C9191B959500CC9B4F /* MJCountry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJCountry.h; sourceTree = "<group>"; };
D2B776CA191B959500CC9B4F /* MJCountry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJCountry.m; sourceTree = "<group>"; };
D2B776CB191B959500CC9B4F /* MJParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJParser.h; sourceTree = "<group>"; };
D2B776CC191B959500CC9B4F /* MJParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJParser.m; sourceTree = "<group>"; };
D2B776CD191B959500CC9B4F /* MJPerson.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJPerson.h; sourceTree = "<group>"; };
D2B776CE191B959500CC9B4F /* MJPerson.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJPerson.m; sourceTree = "<group>"; };
D2B776CF191B959500CC9B4F /* MJProject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJProject.h; sourceTree = "<group>"; };
D2B776D0191B959500CC9B4F /* MJProject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJProject.m; sourceTree = "<group>"; };
D2B776D1191B959500CC9B4F /* data_25MB.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = data_25MB.json; sourceTree = "<group>"; };
D2B776D8191B95EA00CC9B4F /* MJPerformanceTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJPerformanceTest.h; sourceTree = "<group>"; };
D2B776D9191B95EA00CC9B4F /* MJPerformanceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJPerformanceTest.m; sourceTree = "<group>"; };
D2C3463318959EF2005B6B5C /* Motis.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Motis.app; sourceTree = BUILT_PRODUCTS_DIR; };
D2C3463618959EF2005B6B5C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
D2C3463818959EF2005B6B5C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
D2C3463A18959EF2005B6B5C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
D2C3464F18959EF2005B6B5C /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
D2C890141A0ABBD700E81A9D /* MJPerformanceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJPerformanceTest.m; sourceTree = "<group>"; };
D2C890171A0ABC2900E81A9D /* data_25MB.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = data_25MB.json; sourceTree = "<group>"; };
D2C890181A0ABC2900E81A9D /* MJCompany.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJCompany.h; sourceTree = "<group>"; };
D2C890191A0ABC2900E81A9D /* MJCompany.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJCompany.m; sourceTree = "<group>"; };
D2C8901A1A0ABC2900E81A9D /* MJCountry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJCountry.h; sourceTree = "<group>"; };
D2C8901B1A0ABC2900E81A9D /* MJCountry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJCountry.m; sourceTree = "<group>"; };
D2C8901C1A0ABC2900E81A9D /* MJParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJParser.h; sourceTree = "<group>"; };
D2C8901D1A0ABC2900E81A9D /* MJParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJParser.m; sourceTree = "<group>"; };
D2C8901E1A0ABC2900E81A9D /* MJPerson.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJPerson.h; sourceTree = "<group>"; };
D2C8901F1A0ABC2900E81A9D /* MJPerson.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJPerson.m; sourceTree = "<group>"; };
D2C890201A0ABC2900E81A9D /* MJProject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJProject.h; sourceTree = "<group>"; };
D2C890211A0ABC2900E81A9D /* MJProject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJProject.m; sourceTree = "<group>"; };
D2DD9FCB192DF28400163C50 /* MJMotisObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJMotisObject.h; sourceTree = "<group>"; };
D2DD9FCC192DF28400163C50 /* MJMotisObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJMotisObject.m; sourceTree = "<group>"; };
D2DD9FCD192DF28400163C50 /* MJMotisObjectNonRestricted.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJMotisObjectNonRestricted.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -146,6 +145,8 @@
children = (
D2A0544D18D8A5B80050DE68 /* MJValidationTest.m */,
D2DD9FCA192DF28400163C50 /* Validation Test */,
D2C890141A0ABBD700E81A9D /* MJPerformanceTest.m */,
D2C890161A0ABC2900E81A9D /* Performance Test */,
D2E3E02F190E8D82002BD141 /* MJHierarchyTest.m */,
D2E3E031190E8D88002BD141 /* Hierarchy Test */,
D2A0544818D8A5B80050DE68 /* Supporting Files */,
Expand Down Expand Up @@ -184,26 +185,6 @@
name = Example;
sourceTree = "<group>";
};
D2B776C6191B959500CC9B4F /* Performance Test */ = {
isa = PBXGroup;
children = (
D2B776D8191B95EA00CC9B4F /* MJPerformanceTest.h */,
D2B776D9191B95EA00CC9B4F /* MJPerformanceTest.m */,
D2B776C7191B959500CC9B4F /* MJCompany.h */,
D2B776C8191B959500CC9B4F /* MJCompany.m */,
D2B776C9191B959500CC9B4F /* MJCountry.h */,
D2B776CA191B959500CC9B4F /* MJCountry.m */,
D2B776CB191B959500CC9B4F /* MJParser.h */,
D2B776CC191B959500CC9B4F /* MJParser.m */,
D2B776CD191B959500CC9B4F /* MJPerson.h */,
D2B776CE191B959500CC9B4F /* MJPerson.m */,
D2B776CF191B959500CC9B4F /* MJProject.h */,
D2B776D0191B959500CC9B4F /* MJProject.m */,
D2B776D1191B959500CC9B4F /* data_25MB.json */,
);
path = "Performance Test";
sourceTree = "<group>";
};
D2C3462A18959EF2005B6B5C = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -244,7 +225,6 @@
D2DF757818D746A800163BA8 /* MJAppDelegate.m */,
D2B776C4191B957000CC9B4F /* Motis */,
D2B776C5191B957700CC9B4F /* Example */,
D2B776C6191B959500CC9B4F /* Performance Test */,
D2C3463D18959EF2005B6B5C /* Supporting Files */,
);
path = Motis;
Expand All @@ -261,6 +241,24 @@
name = "Supporting Files";
sourceTree = "<group>";
};
D2C890161A0ABC2900E81A9D /* Performance Test */ = {
isa = PBXGroup;
children = (
D2C890171A0ABC2900E81A9D /* data_25MB.json */,
D2C890181A0ABC2900E81A9D /* MJCompany.h */,
D2C890191A0ABC2900E81A9D /* MJCompany.m */,
D2C8901A1A0ABC2900E81A9D /* MJCountry.h */,
D2C8901B1A0ABC2900E81A9D /* MJCountry.m */,
D2C8901C1A0ABC2900E81A9D /* MJParser.h */,
D2C8901D1A0ABC2900E81A9D /* MJParser.m */,
D2C8901E1A0ABC2900E81A9D /* MJPerson.h */,
D2C8901F1A0ABC2900E81A9D /* MJPerson.m */,
D2C890201A0ABC2900E81A9D /* MJProject.h */,
D2C890211A0ABC2900E81A9D /* MJProject.m */,
);
path = "Performance Test";
sourceTree = "<group>";
};
D2DD9FCA192DF28400163C50 /* Validation Test */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -366,14 +364,14 @@
buildActionMask = 2147483647;
files = (
D2A0544C18D8A5B80050DE68 /* InfoPlist.strings in Resources */,
D2C890221A0ABC2900E81A9D /* data_25MB.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D2C3463118959EF2005B6B5C /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D2B776D7191B959500CC9B4F /* data_25MB.json in Resources */,
D2DF758118D746AF00163BA8 /* Images.xcassets in Resources */,
D21D6FB218D7470D000E620B /* InfoPlist.strings in Resources */,
);
Expand All @@ -387,31 +385,31 @@
buildActionMask = 2147483647;
files = (
D2DD9FD5192DF28400163C50 /* MJMotisObjectWithFormatter.m in Sources */,
D2C890251A0ABC2900E81A9D /* MJParser.m in Sources */,
D2A0544E18D8A5B80050DE68 /* MJValidationTest.m in Sources */,
D2C890271A0ABC2900E81A9D /* MJProject.m in Sources */,
D2E3E03B190E8DCA002BD141 /* MJChildB.m in Sources */,
D2C890231A0ABC2900E81A9D /* MJCompany.m in Sources */,
D2DD9FD6192DF28400163C50 /* MJTestObject.m in Sources */,
D2C890241A0ABC2900E81A9D /* MJCountry.m in Sources */,
D2C890261A0ABC2900E81A9D /* MJPerson.m in Sources */,
D2E3E038190E8DBF002BD141 /* MJChildA.m in Sources */,
D2DD9FD3192DF28400163C50 /* MJMotisObject.m in Sources */,
D2E3E034190E8D9E002BD141 /* MJParentObject.m in Sources */,
D2DD9FD4192DF28400163C50 /* MJMotisObjectNonRestricted.m in Sources */,
D2E3E030190E8D82002BD141 /* MJHierarchyTest.m in Sources */,
D2C890151A0ABBD700E81A9D /* MJPerformanceTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D2C3462F18959EF2005B6B5C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D2B776D5191B959500CC9B4F /* MJPerson.m in Sources */,
D2DF757E18D746A800163BA8 /* MJUser.m in Sources */,
D2B776D4191B959500CC9B4F /* MJParser.m in Sources */,
D2DF757F18D746A800163BA8 /* MJVideo.m in Sources */,
D2B776D2191B959500CC9B4F /* MJCompany.m in Sources */,
D2B776D3191B959500CC9B4F /* MJCountry.m in Sources */,
D2DF758518D746C200163BA8 /* main.m in Sources */,
D2DF757D18D746A800163BA8 /* MJAppDelegate.m in Sources */,
D2B776D6191B959500CC9B4F /* MJProject.m in Sources */,
D2B776DA191B95EA00CC9B4F /* MJPerformanceTest.m in Sources */,
D21D6FB518D74717000E620B /* NSObject+Motis.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
BlueprintName = "Motis Tests"
ReferencedContainer = "container:Motis.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "MJPerformanceTest">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
<MacroExpansion>
Expand Down
21 changes: 1 addition & 20 deletions SampleProject/Motis/MJAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,14 @@

#import "Motis.h"

#if PERFORMANCE_TEST
#import "MJPerformanceTest.h"
#else
#import "MJVideo.h"
#import "MJUser.h"
#endif

@implementation MJAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if PERFORMANCE_TEST
[self testMotisPerformance];
#else
[self testMotis]; // <--- UNCOMMENT FOR TESTING
#endif
//[self testMotis]; // <--- UNCOMMENT FOR TESTING

UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = [[UIViewController alloc] init];
Expand All @@ -47,16 +39,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

#pragma mark Private Methods

#if PERFORMANCE_TEST

- (void)testMotisPerformance
{
MJPerformanceTest *test = [[MJPerformanceTest alloc] init];
[test start];
}

#else

- (void)testMotis
{
// Defining a JSONDictionary
Expand Down Expand Up @@ -116,6 +98,5 @@ - (void)testMotis
NSLog(@"AFTER parsing: %@", video.mts_extendedObjectDescription);
NSLog(@"video.privateVideoKey: %@",[video.privateVideoKey description]);
}
#endif

@end
15 changes: 0 additions & 15 deletions SampleProject/Motis/Performance Test/MJPerformanceTest.h

This file was deleted.

Loading

0 comments on commit 26a47e4

Please sign in to comment.