找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 4911|回复: 3

[已解决] 语句执行时间比较

30

主题

116

帖子

116

积分

侠客

积分
116
chenmengdan 发表于 2016-10-12 10:45:05 | 显示全部楼层 |阅读模式
>>> timeit np.dot(np.array([1,2,3]),np.array([1,2,3]))
>>>The slowest run took 5.85 times longer than the fastest. This could mean that an intermediate result is being cached
        100000 loops, best of 3: 4.74 µs per loop

>>>timeit np.dot([1,2,3],np.array([1,2,3]))
>>>The slowest run took 7.57 times longer than the fastest. This could mean that an intermediate result is being cached
        100000 loops, best of 3: 4.67 µs per loop


这两句到底哪个耗时少点

回复

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2016-10-13 20:11:26 | 显示全部楼层
没有用过timeit. 网上有人提问得到如下回应:

The message "intermediate result is being cached" is just a blind guess in the canned message reported by %timeit. It may or may not be true, and you should not assume it is correct.


In particular, one of the most common reasons for the first run being slowest is that the array is in the CPU cache only after the first run.

CPUs cache things automatically; you cannot avoid this, and you don't really want to avoid it. However, optimizing algorithms so that CPU caches can work optimally is nowadays one of the bottlenecks that high-performance computing needs to take into account.

意思大致是说第一句的那个时间可以忽略, 是由于CPU缓存多用了一点时间.
从后面的时间看. 应该是第二个语句耗时少点.
回复 支持 1 反对 0

使用道具 举报

30

主题

116

帖子

116

积分

侠客

积分
116
chenmengdan  楼主| 发表于 2016-10-14 09:10:33 | 显示全部楼层
whydo1 发表于 2016-10-13 20:11
没有用过timeit. 网上有人提问得到如下回应:

The message "intermediate result is being cached" is just ...

哦,好的,我知道了,多谢
回复 支持 反对

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2016-10-14 20:52:03 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表