storyboard创建vc的速度会影响用户体验吗?以下做了一个简单的数据统计。
storyboard创建的vc如图所示:
为了对比创建速度,同时也用代码创建uiviewcontroller。
代码如下:
NSDate *begain = [NSDate date];
NSLog(@"SB开始时间%@", begain);
for (int i = 0; i < 100; i ++) {
TestSbVC *testVC = [TestSbVC creat];
}
NSDate *end = [NSDate date];
NSLog(@"SB结束时间%@", end);
NSTimeInterval interval = [end timeIntervalSinceDate:begain];
NSLog(@"SB时间%f", interval * 1000);
TimeModel *model = [TimeModel new];
model.sbBegin = begain;
model.sbEnd = end;
model.sbInterval = interval;
begain = [NSDate date];
NSLog(@"开始时间%@", begain);
for (int i = 0; i < 100; i ++) {
UIViewController *VC = [[UIViewController alloc] init];
}
end = [NSDate date];
NSLog(@"结束时间%@", end);
interval = [end timeIntervalSinceDate:begain];
NSLog(@"时间%f", interval * 1000);
model.begin = begain;
model.end = end;
model.interval = interval;
[self.array addObject:model];
其中TimeModel是创建时间花费统计,可以在统计页面展示。
使用iOS12.4.6, iPhone 6p上的时间统计为:
2020-09-29 15:32:52.988282+0800 test[49975:1544313] SB开始时间2020-09-29 07:32:52 +0000
2020-09-29 15:32:53.173188+0800 test[49975:1544313] SB结束时间2020-09-29 07:32:53 +0000
2020-09-29 15:32:53.173406+0800 test[49975:1544313] SB时间193.354011
2020-09-29 15:32:53.173722+0800 test[49975:1544313] 开始时间2020-09-29 07:32:53 +0000
2020-09-29 15:32:53.181798+0800 test[49975:1544313] 结束时间2020-09-29 07:32:53 +0000
2020-09-29 15:32:53.182017+0800 test[49975:1544313] 时间8.042097
2020-09-29 15:32:54.110151+0800 test[49975:1544313] SB开始时间2020-09-29 07:32:54 +0000
2020-09-29 15:32:54.225197+0800 test[49975:1544313] SB结束时间2020-09-29 07:32:54 +0000
2020-09-29 15:32:54.225394+0800 test[49975:1544313] SB时间115.046024
2020-09-29 15:32:54.225630+0800 test[49975:1544313] 开始时间2020-09-29 07:32:54 +0000
2020-09-29 15:32:54.233182+0800 test[49975:1544313] 结束时间2020-09-29 07:32:54 +0000
2020-09-29 15:32:54.233407+0800 test[49975:1544313] 时间7.591009
2020-09-29 15:32:55.362325+0800 test[49975:1544313] SB开始时间2020-09-29 07:32:55 +0000
2020-09-29 15:32:55.501803+0800 test[49975:1544313] SB结束时间2020-09-29 07:32:55 +0000
2020-09-29 15:32:55.502035+0800 test[49975:1544313] SB时间139.551044
2020-09-29 15:32:55.502278+0800 test[49975:1544313] 开始时间2020-09-29 07:32:55 +0000
2020-09-29 15:32:55.510036+0800 test[49975:1544313] 结束时间2020-09-29 07:32:55 +0000
2020-09-29 15:32:55.510247+0800 test[49975:1544313] 时间7.810950
2020-09-29 15:32:56.429088+0800 test[49975:1544313] SB开始时间2020-09-29 07:32:56 +0000
2020-09-29 15:32:56.576633+0800 test[49975:1544313] SB结束时间2020-09-29 07:32:56 +0000
2020-09-29 15:32:56.577194+0800 test[49975:1544313] SB时间147.638917
2020-09-29 15:32:56.577745+0800 test[49975:1544313] 开始时间2020-09-29 07:32:56 +0000
2020-09-29 15:32:56.585649+0800 test[49975:1544313] 结束时间2020-09-29 07:32:56 +0000
2020-09-29 15:32:56.585854+0800 test[49975:1544313] 时间7.885933
2020-09-29 15:32:57.512637+0800 test[49975:1544313] SB开始时间2020-09-29 07:32:57 +0000
2020-09-29 15:32:57.653432+0800 test[49975:1544313] SB结束时间2020-09-29 07:32:57 +0000
2020-09-29 15:32:57.653680+0800 test[49975:1544313] SB时间140.890002
2020-09-29 15:32:57.653924+0800 test[49975:1544313] 开始时间2020-09-29 07:32:57 +0000
2020-09-29 15:32:57.661614+0800 test[49975:1544313] 结束时间2020-09-29 07:32:57 +0000
2020-09-29 15:32:57.661874+0800 test[49975:1544313] 时间7.732987
2020-09-29 15:32:59.244159+0800 test[49975:1544313] SB开始时间2020-09-29 07:32:59 +0000
2020-09-29 15:32:59.353919+0800 test[49975:1544313] SB结束时间2020-09-29 07:32:59 +0000
2020-09-29 15:32:59.354088+0800 test[49975:1544313] SB时间109.764934
2020-09-29 15:32:59.354331+0800 test[49975:1544313] 开始时间2020-09-29 07:32:59 +0000
2020-09-29 15:32:59.362000+0800 test[49975:1544313] 结束时间2020-09-29 07:32:59 +0000
2020-09-29 15:32:59.362153+0800 test[49975:1544313] 时间7.681966
2020-09-29 15:33:01.127798+0800 test[49975:1544313] SB开始时间2020-09-29 07:33:01 +0000
2020-09-29 15:33:01.242754+0800 test[49975:1544313] SB结束时间2020-09-29 07:33:01 +0000
2020-09-29 15:33:01.242961+0800 test[49975:1544313] SB时间115.002036
2020-09-29 15:33:01.243250+0800 test[49975:1544313] 开始时间2020-09-29 07:33:01 +0000
2020-09-29 15:33:01.250293+0800 test[49975:1544313] 结束时间2020-09-29 07:33:01 +0000
2020-09-29 15:33:01.250493+0800 test[49975:1544313] 时间7.086039
2020-09-29 15:33:02.945304+0800 test[49975:1544313] SB开始时间2020-09-29 07:33:02 +0000
2020-09-29 15:33:03.082992+0800 test[49975:1544313] SB结束时间2020-09-29 07:33:03 +0000
2020-09-29 15:33:03.083216+0800 test[49975:1544313] SB时间137.732983
2020-09-29 15:33:03.083519+0800 test[49975:1544313] 开始时间2020-09-29 07:33:03 +0000
2020-09-29 15:33:03.090863+0800 test[49975:1544313] 结束时间2020-09-29 07:33:03 +0000
2020-09-29 15:33:03.091004+0800 test[49975:1544313] 时间7.305980
2020-09-29 15:33:04.228398+0800 test[49975:1544313] SB开始时间2020-09-29 07:33:04 +0000
2020-09-29 15:33:04.346177+0800 test[49975:1544313] SB结束时间2020-09-29 07:33:04 +0000
2020-09-29 15:33:04.346342+0800 test[49975:1544313] SB时间117.792010
2020-09-29 15:33:04.346456+0800 test[49975:1544313] 开始时间2020-09-29 07:33:04 +0000
2020-09-29 15:33:04.353704+0800 test[49975:1544313] 结束时间2020-09-29 07:33:04 +0000
2020-09-29 15:33:04.353839+0800 test[49975:1544313] 时间7.212996
2020-09-29 15:33:05.463415+0800 test[49975:1544313] SB开始时间2020-09-29 07:33:05 +0000
2020-09-29 15:33:05.609531+0800 test[49975:1544313] SB结束时间2020-09-29 07:33:05 +0000
2020-09-29 15:33:05.610099+0800 test[49975:1544313] SB时间146.219969
2020-09-29 15:33:05.610673+0800 test[49975:1544313] 开始时间2020-09-29 07:33:05 +0000
2020-09-29 15:33:05.618586+0800 test[49975:1544313] 结束时间2020-09-29 07:33:05 +0000
2020-09-29 15:33:05.618816+0800 test[49975:1544313] 时间7.907987
如图:
通过以上数据可以看出:
storyboard创建vc是直接创建uiviewcontroller时间的15~24倍,(代码创建的vc没有任何控件)。但使用storyboard创建vc一次花费的时间最多也不到2ms,对于人来说是很难感觉出来的。相对转场动画和网络请求,创建vc的时间是很少的。
以上,还是不要纠结通过storyboard创建vc耗时问题了。
代码:https://github.com/kunpo/aaa