图片加载速度分析

  • 测试环境:iPhone5C  IOS8.3
  • 测试代码: 
    NSMutableArray *arr1 = [NSMutableArray arrayWithCapacity:4];
    NSMutableArray *arr2 = [NSMutableArray arrayWithCapacity:4];
    NSMutableArray *arr3 = [NSMutableArray arrayWithCapacity:4];
    
    for (int i = 0; i < 10; i++) {
        
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
        [self.view addSubview:imgView];
        
        // 1
        uint64_t sTime = mach_absolute_time();
        UIImage *img = [UIImage imageNamed:@"yulian_launch_0"];
        uint64_t eTime = mach_absolute_time();
        
        uint64_t elapsed = eTime - sTime;
        NSLog(@"1.%lld", elapsed);
        [arr1 addObject:@(elapsed)];
        
        UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(100, 250, 100, 100)];
        [self.view addSubview:imgView1];
       
        // 2
        NSString *path = [[NSBundle mainBundle] pathForResource:@"yulian_launch_1" ofType:@"png"];
        sTime = mach_absolute_time();
        UIImage *img1 = [[UIImage alloc] initWithContentsOfFile:path];
        eTime = mach_absolute_time();
        elapsed = eTime - sTime;
        NSLog(@"2.%lld", elapsed);
        [arr2 addObject:@(elapsed)];
        
        UIImageView *imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(100, 400, 100, 100)];
        [self.view addSubview:imgView2];
        
        // 3
        NSString *path1 = [[NSBundle mainBundle] pathForResource:@"yulian_launch_2" ofType:@"png"];
        sTime = mach_absolute_time();
        NSData *imageD = [NSData dataWithContentsOfFile:path1];
        UIImage *img2 = [UIImage imageWithData:imageD];
        eTime = mach_absolute_time();
        elapsed = eTime - sTime;
        NSLog(@"3.%lld", elapsed);
        [arr3 addObject:@(elapsed)];
    }

 

  • 执行耗时,单位纳秒

 

  • 折线图可以直观的看出来,执行时间的差别,后两者是差不多,非缓存的执行时间大约是imageName的6倍(除首次)

imageName个人建议还是小图多次使用的场景使用。

其他两个大图或使用较少使用。

 

 

转载于:https://my.oschina.net/petsatan/blog/681003

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值