前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >字典转模型速度比较

字典转模型速度比较

作者头像
程序员不务正业
发布2018-06-12 15:36:53
5300
发布2018-06-12 15:36:53
举报
文章被收录于专栏:移动端周边技术扩展

同样运行100000次后的结果,哈哈不是说mj就不行,mj代码量和兼容程度是yy不能比的

代码语言:javascript
复制
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

测试代码

代码语言:javascript
复制
#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
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018.06.09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档