Skip to content

finish homework 4 #34

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

finish homework 4 #34

wants to merge 5 commits into from

Conversation

hebangwen
Copy link

注意,下面的优化都是在上面的优化基础上进行的

优化方法 时间 原因
1877 ms  
从循环中提取常量,打开 fmath 和 -march=native 优化 1190 ms 提取计算不变量,减少运算次数。fmath 能够让 GCC 尝试使用更高效的浮点数优化,-march=native 让 GCC 编译器使用本机自带的更高效的一些寄存器或者硬件
使用 soa 1119 ms 优化内存布局,有利于 SIMD,但是这里的加速比并不高。
使用 array 而不是 vector,加上使用 unroll 274 ms 从 vector 换成 array 之后,提升非常明显。使用在栈上分配大小的容器,有利于编译器的优化。

为什么在栈上会有利于优化,这一点我还不是很理解。猜测的原因:栈上的数据只会保存在这个数据段中,当栈退出后,数据就不会被清空了,所以它更有利于优化;栈空间比较小,搜索空间比堆空间要小,编译器不要做很多复杂的工作。

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant