字典转模型速度比较

同样运行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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容