查看代码运行时间
来源:互联网 发布:海信液晶电视网络升级 编辑:程序博客网 时间:2024/05/17 06:20
有时候我们想要准确的知道某段代码、某个循环执行的时间,然后分析效率等问题,这个时候就需要执行时间是多少。正好看到网上已经有人做了这个工作,我就直接摘下来了。正好也用了宏的方式计算时间,我们只要在需要计算时间的代码块前后写上TICK,TOCK宏即可。当然,原理也是非常的简单,也就是使用NSDate计算差值。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#import "ViewController.h"
#define TICK NSDate *startTime = [NSDate date]
#define TOCK NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[
super
viewDidLoad];
TICK;
for
(int i = 0; i < 5; i++) {
NSLog(@
"我的值:%d"
,i);
}
TOCK;
}
@end
1 0
- 查看代码运行时间
- 查看程序运行时间的代码
- iOS 如何查看一段代码运行的时间
- 对程序进行评测之查看代码运行时间
- python中查看代码的运行时间方法
- 查看系统运行时间
- iar查看运行时间
- MySQL查看运行时间
- 查看进程运行时间
- 查看 服务运行时间
- 查看虚拟机运行时间
- 使用keil的调试模式查看代码运行时间(以51单片机代码为例)
- 查看脚本运行时间命令
- 查看mysql语句运行时间
- Linux 查看系统运行时间
- 查看Java程序运行时间
- 查看mysql语句运行时间
- python:查看程序运行时间
- C++ 内存池 -- C++ Memory Pool
- 在ubuntu14.04上使用Android SDK创建模拟失败
- 【杭电oj】1787 - GCD Again(欧拉函数)
- [initandlisten] exception in initAndListen: 28663 Cannot start server
- Android日志工具类
- 查看代码运行时间
- File upload error - unable to create a temporary file
- 银联常用8583报文域说明--个人整理20160322
- 使用Volley异步加载网络图片
- __cplusplus
- 怎么为PDF文档添加和删除页面
- 用eclipse打包apk和遇到的问题
- Linux 实践 01:Centos 7 minimal 安装配置及桌面安装
- SharePoint2013 IT Professional - Image Rendition