欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

量化交易之算法篇

时间:2023-05-28

//// Created by win10 on 2021/11/16.//#include #include using namespace std;int fibo_1(int index) { // 这个算法性能上有问题, index为64时不出结果 if (index <= 1) return index; return fibo_1(index - 2) + fibo_1(index - 1);}int fibo_2(int index) { if (index <= 1) return index; int first(0); int second(1); for (size_t i(0); i < index - 1; i++) { int sumValue = first + second; first = second; second = sumValue; } return second;}templatedouble checkTime(T&& checkFunction, int index) { using namespace std::chrono; auto start = system_clock::now(); checkFunction(index); duration diff = system_clock::now() - start; std::cout << "time diff:" << diff.count() << std::endl; return diff.count();}int main() { int valueIndex = 20; double fibo_1_time = checkTime(fibo_1, valueIndex); double fibo_2_time = checkTime(fibo_2, valueIndex); if (fibo_1_time > fibo_2_time) { std::cout << "fibo_1_time big" << std::endl; } else if (fibo_1_time < fibo_2_time) { std::cout << "fibo_2_time big" << std::endl; } else { std::cout << "onaji" << std::endl; } return 0;}

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。