Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add some speed-up tricks #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

SkySailing
Copy link

电脑硬件:
Intel(R) Xeon(R) CPU E5-2678 v3 @ 2.50GHz

final result:
6285 ms / 1096 ms = 5.734

优化过程如下:
原始版本
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 6285 ms

-o1 优化
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 2659 ms

-o2
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 2558 ms

-o3
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 2560 ms

索引int变成size_t
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 2560 ms

inline frand函数
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 2593 ms

将/2改成*0.5
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 2585 ms

将公共除法变成乘法
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 2030 ms

-ffast-math 选项定义了预处理器宏 FAST_MATH, 指示编译不必遵循 IEEE 和 ISO 的浮点运算标准
-march=native,GCC会自动检测你的CPU支持的指令集。
Initial energy: -13.414000
Final energy: -13.356841
Time elapsed: 1606 ms

SoA 阵列结构 struct of array
Initial energy: -13.414000
Final energy: -13.356841
Time elapsed: 1630 ms

sqrt前+std:: 使用模板完成传入参数匹配
Initial energy: -13.414000
Final energy: -13.356841
Time elapsed: 1220 ms

#pragma GCC unroll 4
Initial energy: -13.414000
Final energy: -13.356841
Time elapsed: 1212 ms

G * dt / d2 提取到循环外面计算
Initial energy: -13.414000
Final energy: -13.356841
Time elapsed: 1096 ms

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

Successfully merging this pull request may close these issues.

1 participant