《iOS和macOS性能优化读书笔记之一》

这篇博客探讨了iOS和macOS应用的性能优化,首先介绍了CPU原理,指出OC使用基本类型进行计算的时间效率,以及对象创建的性能问题。接着,讨论了测量和优化工具,包括top、time、sample命令,以及Xcode的Instruments,强调了Time Profile在定位性能瓶颈上的作用,并提供了如何深入分析和优化代码的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、CPU原理

  • OC是一种混编语言,如果你在计算过程中采用基本的类型比如int, double等计算时间非常小,比Swift,Java采用基本数据类型计算还小。如果是采用OC的类型,比如NSNumber等,就会比较耗时。
  • OC在快速创建对象时,比其他纯粹的面向对象的语言要慢。
  • 复杂度计算,通过indexOfObject实现的隐式二次算法的例子,如果传入参数是一个数组,使用indexOfObject方法执行检查时,执行次数为O(m),如果该成NSSet,已经摊销了 O(1)用于检查存在。

二、测量和工具

  • top 在命令行输入:top -u 命令

  • time 命令

  • sample 命令,配合top命令和time命令查看具体信息

  • Xcode测量工具:打开Xcode主窗口左侧的调试导航器(command+7)

  • Instrument:作为一个功能强大的采样工具,它的输出信息通常是指示性的不是定性的。

  • instrument 设置和收集数据:Xcode->Production->Profile->Time Profile启动时间分析工具。点击file->RecordingOption->Time Limited 设置检测时间限制

  • instrument 基本分析:详细信息视图中的每一行显示单个函数或方法,对于每个函数,显示当前函数和子函数的总运行时间(以毫秒为单位)。小图标表示函数的来源,头像表示用户ÿ

iOS and Macos Performance Tuning: Cocoa, Cocoa Touch, Objective-C, and Swift (Developer's Library) by Marcel Weiher English | 3 Mar. 2017 | ISBN: 0321842847 | 400 Pages | EPUB/PDF (conv) | 42.64 MB In iOS and macOS™ Performance Tuning, Marcel Weiher drills down to the code level to help you systematically optimize CPU, memory, I/O, graphics, and program responsiveness in any Objective-C, Cocoa, or CocoaTouch program. This up-to-date guide focuses entirely on performance optimization for macOS and iOS. Drawing on 25 years of experience optimizing Apple device software, Weiher identifies concrete performance problems that can be discovered empirically via measurement. Then, based on a deep understanding of fundamental principles, he presents specific techniques for solving them. Weiher presents insights you won’t find anywhere else, most of them applying to both macOS and iOS development. Throughout, he reveals common pitfalls and misconceptions about Apple device performance, explains the realities, and helps you reflect those realities in code that performs beautifully. Understand optimization principles, measurement, tools, pitfalls, and techniques Recognize when to carefully optimize, and when it isn’t worth your time Balance performance and encapsulation to create efficient object representations, communication, data access, and computation Avoid mistakes that slow down Objective-C programs and hinder later optimization Fix leaks and other problems with memory and resource management Address I/O issues associated with drives, networking, serialization, and SQLite Code graphics and UIs that don’t overwhelm limited iOS device resources Learn what all developers need to know about Swift performance
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值