同样运行100000次后的结果,哈哈不是说mj就不行,mj代码量和兼容程度是yy不能比的
2018-06-09 16:57:08.757885+0800 04-YY和MJ转模型的对比[16298:12944014] YY - 0.19
2018-06-09 16:57:13.636412+0800 04-YY和MJ转模型的对比[16298:12944014] MJ - 4.88
2018-06-09 16:57:13.734706+0800 04-YY和MJ转模型的对比[16298:12944014] 系统kvo - 0.10
测试代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
BookDTO *bDto1 = [[BookDTO alloc] init];
bDto1.bookName = @"JinPingMei";
BookDTO *bDto2 = [[BookDTO alloc] init];
bDto2.bookName = @"ShuiHu";
BookDTO *bDto3 = [[BookDTO alloc] init];
bDto3.bookName = @"XiYouJi";
NSDictionary *dic = @{
@"name" : @"mawenxing",
@"age" : @18,
@"book" :bDto1,
@"books" :
@[bDto2,bDto3]
};
[self test1Time:dic];
[self test2Time:dic];
[self test3Time:dic];
}
/** 测试`YY`转模型100000次 */
-(void)test1Time:(NSDictionary *)dic{
CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < 100000; ++i) {
UserDTO *dto = [UserDTO yy_modelWithDictionary:dic];
}
NSLog(@"YY - %.2f",CFAbsoluteTimeGetCurrent()-start);
}
/** 测试`MJ`转模型100000次 */
-(void)test2Time:(NSDictionary *)dic{
CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < 100000; ++i) {
UserDTO *dto = [UserDTO mj_objectWithKeyValues:dic];
}
NSLog(@"MJ - %.2f",CFAbsoluteTimeGetCurrent()-start);
}
/** 测试系统kvo转模型100000次 */
- (void)test3Time:(NSDictionary *)dic {
CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
for (int i = 0; i < 100000; i++) {
UserDTO *dto = [UserDTO userDtoWithDict:dic];
}
NSLog(@"系统kvo - %.2f", CFAbsoluteTimeGetCurrent()-start);
}
@end
网友评论