iOS 如何查看一段代码运行的时间

http://www.jianshu.com/p/221507eb8590?utm_source=open-open     ios开发的一些小技巧篇一

1.如何快速的查看一段代码的执行时间。

#define TICK   NSDate *startTime = [NSDate date]
#define TOCK   NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])

在想要查看执行时间的代码的地方进行这么处理

TICK
//do your work here
TOCK

2.如何快速查看一个函数的调用次数,且不添加一句代码。 如下图

look Hitcount
look Hitcount

这种方法适合于一个if方法,一个for循环,而且不会中断程序,切不需要加一句代码。但是一定要记得选中下面的automatically continue after evaluting actions;

3.在使用view的缩放的时候,layer.border.width随着view的放大,会出现锯齿化的问题,解决这个问题需要设置这个属性。

self.layer.allowsEdgeAntialiasing = YES;

4.instrument中time profile 中的self, #self,%self各代表什么 ?

self
self

下面引用了一下网上的具体内容

Self is "The number of times the symbol calls itself." according to the Apple Docs on the Time Profiler.

From the way the numbers look though, it seems self is the summed duration of samples that had this symbol at the bottom of its stack trace. That would make:

self: the number of samples where this symbol was at the bottom of the stack trace
% self: the percent of self samples relative to total samples of currently displayed call tree
(eg - #self / total samples).
So this wouldn't tell you how many times a method was called. But it would give you an idea how much time is spent in a method or lower in the call tree.

6.如何快速添加一个全局异常断点,(一步顶三步)。和添加一个symbloic断点,(一步还是顶三步)添加一个断点不使用鼠标

add breakPoint
add breakPoint

看到图了吧,加这些断点完全不需要动一下鼠标(恕我吹牛B了),加单独断点的时候动了下鼠标,但那是我故意让你们看到我是有鼠标的。

  • 首先All Exception断点是我们很常用的,这个我是这样用一个快捷键做到的!通过改键command +p 为加异常断点的,要说怎么改,翻我以前博客去!
  • 然后加symbloic的快捷键为commnamd + option + \
  • 加一个单独一行断点的快捷键为command + \


文/kissGod(简书作者)
原文链接:http://www.jianshu.com/p/221507eb8590
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

好的,这里是一段简单的 iOS OpenGL 代码,可以在 Xcode 中运行: ```objective-c #import <GLKit/GLKit.h> @interface ViewController : GLKViewController @property (nonatomic, strong) EAGLContext *context; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; GLKView *view = (GLKView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; [EAGLContext setCurrentContext:self.context]; // 设置 OpenGL 状态 glClearColor(0.0, 0.0, 0.0, 1.0); // 初始化顶点数组和索引数组 GLfloat vertices[] = { -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 0.0, 1.0, 0.0 }; GLuint indices[] = {0, 1, 2}; // 创建顶点缓冲对象和索引缓冲对象 GLuint vertexBuffer, indexBuffer; glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glGenBuffers(1, &indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); } - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { glClear(GL_COLOR_BUFFER_BIT); // 启用顶点属性数组 glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 0, NULL); // 绘制三角形 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, NULL); // 关闭顶点属性数组 glDisableVertexAttribArray(GLKVertexAttribPosition); } @end ``` 这段代码创建了一个 GLKViewController,用于管理 OpenGL 渲染上下文和视图。在 viewDidLoad 方法中,我们创建了一个 OpenGL ES 3.0 的渲染上下文,并将其绑定到 GLKView 上。然后,我们设置了 OpenGL 的状态,包括背景颜色和顶点数组。 在 glkView:drawInRect: 方法中,我们清空了颜色缓冲区,启用了顶点属性数组,并绘制了一个三角形。最后,我们关闭了顶点属性数组。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值