Skip to content

Commit 93e466f

Browse files
committed
Re-work
1 parent 5abb054 commit 93e466f

File tree

1 file changed

+12
-117
lines changed

1 file changed

+12
-117
lines changed

extension/apple/Benchmark/Tests/Tests.mm

Lines changed: 12 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -17,117 +17,20 @@
1717
using namespace ::executorch::extension;
1818
using namespace ::executorch::runtime;
1919

20-
@interface BenchmarkModel : NSObject
21-
22-
// The model name, i.e. stories110M
23-
@property NSString *name;
24-
@property NSString *backend;
25-
@property NSString *quantization;
26-
27-
-(instancetype)init: (NSString*)name
28-
backend: (NSString*)backend
29-
quantization: (NSString*)quantization;
30-
31-
+(instancetype)initWithModelName: (NSString*)model;
32-
33-
@end
34-
35-
@implementation BenchmarkModel
36-
37-
-(instancetype)init: (NSString*)name
38-
backend: (NSString*)backend
39-
quantization: (NSString*)quantization {
40-
if (self = [super init]) {
41-
self.name = name;
42-
self.backend = backend;
43-
self.quantization = quantization;
44-
}
45-
return self;
46-
}
47-
48-
+(instancetype)initWithModelName: (NSString*)model {
49-
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\\w+)_(\\w+)_(\\w+)" options:0 error:nil];
50-
NSArray* matches = [regex matchesInString:model options:0 range:NSMakeRange(0, [model length])];
51-
52-
for (NSTextCheckingResult* match in matches) {
53-
return [[BenchmarkModel alloc] init:[model substringWithRange:[match rangeAtIndex:1]]
54-
backend:[model substringWithRange:[match rangeAtIndex:2]]
55-
quantization:[model substringWithRange:[match rangeAtIndex:3]]
56-
];
57-
}
58-
59-
return [[BenchmarkModel alloc] init:model
60-
backend:@""
61-
quantization:@""
62-
];
63-
}
64-
65-
@end
66-
6720
@interface DeviceInfo : NSObject
6821

69-
// The metric name, i.e. TPS
70-
@property NSString *device;
71-
72-
// The phone model and Android release version
73-
@property NSString *arch;
74-
@property NSString *os;
75-
// TODO (huydhn): These are not used yet
76-
@property NSNumber *totalMem;
77-
@property NSNumber *availMem;
78-
79-
-(instancetype)init;
22+
+(NSString *)getDeviceInfo;
8023

8124
@end
8225

8326
@implementation DeviceInfo
8427

85-
-(instancetype)init {
86-
self.device = [[UIDevice currentDevice] model];
87-
self.arch = [[UIDevice currentDevice] name];
88-
self.os = [NSString stringWithFormat:@"%@ / %@", [[UIDevice currentDevice] systemName], [[UIDevice currentDevice] systemVersion]];
89-
self.totalMem = [[NSNumber alloc] initWithInt:0];
90-
self.availMem = [[NSNumber alloc] initWithInt:0];
91-
return self;
92-
}
93-
94-
@end
95-
96-
@interface BenchmarkMetric : NSObject
97-
98-
@property BenchmarkModel *benchmarkModel;
99-
100-
// The metric name, i.e. TPS
101-
@property NSString *metric;
102-
103-
// The actual value and the option target value
104-
@property NSNumber *actualValue;
105-
@property NSNumber *targetValue;
106-
107-
@property DeviceInfo *deviceInfo;
108-
109-
-(instancetype)init: (BenchmarkModel*)benchmarkModel
110-
metric: (NSString*)metric
111-
actualValue: (NSNumber*)actualValue
112-
targetValue: (NSNumber*)targetValue
113-
deviceInfo: (DeviceInfo*)deviceInfo;
114-
115-
@end
116-
117-
@implementation BenchmarkMetric
118-
119-
-(instancetype)init: (BenchmarkModel*)benchmarkModel
120-
metric: (NSString*)metric
121-
actualValue: (NSNumber*)actualValue
122-
targetValue: (NSNumber*)targetValue
123-
deviceInfo: (DeviceInfo*)deviceInfo {
124-
125-
self.benchmarkModel = benchmarkModel;
126-
self.metric = metric;
127-
self.actualValue = actualValue;
128-
self.targetValue = targetValue;
129-
self.deviceInfo = deviceInfo;
130-
return self;
28+
+(NSString *)getDeviceInfo {
29+
NSString *device = [[UIDevice currentDevice] model];
30+
NSString *name = [[UIDevice currentDevice] name];
31+
NSString *systemName = [[UIDevice currentDevice] systemName];
32+
NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
33+
return [NSString stringWithFormat:@"%@_%@_%@_%@", device, name, systemName, systemVersion];
13134
}
13235

13336
@end
@@ -141,9 +44,8 @@ + (void)initialize {
14144
if (self != [self class]) {
14245
return;
14346
}
144-
DeviceInfo *deviceInfo = [[DeviceInfo alloc] init];
145-
NSMutableArray *benchmarkMetrics = [[NSMutableArray alloc] init];
146-
47+
NSString *deviceInfo = [DeviceInfo getDeviceInfo];
48+
14749
for (NSBundle *bundle in @[
14850
[NSBundle mainBundle],
14951
[NSBundle bundleForClass:[self class]],
@@ -169,10 +71,9 @@ + (void)initialize {
16971
.lowercaseString;
17072
NSString *modelName =
17173
modelPath.lastPathComponent.stringByDeletingPathExtension;
172-
BenchmarkModel *benchmarkModel = [BenchmarkModel initWithModelName:modelName];
17374

17475
SEL testLoadSelector = NSSelectorFromString([NSString
175-
stringWithFormat:@"test_load_%@_%@", directoryName, modelName]);
76+
stringWithFormat:@"test_load_%@_%@_%@", directoryName, modelName, deviceInfo]);
17677
IMP testLoadImplementation = imp_implementationWithBlock(^(id _self) {
17778
auto __block module = std::make_unique<Module>(modelPath.UTF8String);
17879
[_self measureWithMetrics:@[
@@ -181,14 +82,8 @@ + (void)initialize {
18182
]
18283
options:XCTMeasureOptions.defaultOptions
18384
block:^{
184-
auto status = module->load_method("forward");
185-
BenchmarkMetric *benchmarkMetric = [[BenchmarkMetric alloc] init:benchmarkModel
186-
metric:@"load_status"
187-
actualValue:[[NSNumber alloc] initWithInt:module->is_loaded() ? 0 : 1]
188-
targetValue:0
189-
deviceInfo:deviceInfo];
190-
[benchmarkMetrics addObject:benchmarkMetric];
191-
XCTAssertEqual(status, Error::Ok);
85+
XCTAssertEqual(module->load_method("forward"),
86+
Error::Ok);
19287
}];
19388
});
19489
class_addMethod(

0 commit comments

Comments
 (0)