jhkwei
deepin
2017-12-07 17:57 这程序除了vector 不知道干了什么,其它都不影响,还有就是mingw 是32 位, deepin 是 64 位,建议自己写一个 vector 之类性线表或链表。
Reply Like 0 View the author

https://bbs.deepin.org/post/149735
这程序除了vector 不知道干了什么,其它都不影响,还有就是mingw 是32 位, deepin 是 64 位,建议自己写一 ...
https://bbs.deepin.org/post/149735
g++版本一样吗?
还有关键是vector在加入数据的时候会不断地申请新内存,而申请内存的机制在mingw和linux下 ...
https://bbs.deepin.org/post/149735
想起来好像是哪个知乎大神说的一句话‘一切不看优化选项不看汇编不看profile分析的性能比较都是耍流氓’[jo ...
https://bbs.deepin.org/post/149735
你要是用visual studio 的debug模式,那可能比海参还慢
https://bbs.deepin.org/post/149735
你不应该在追求性能的代码里插入 IO(包括stdio)操作,也就是 cout
https://bbs.deepin.org/post/149735
找到了输出才有意义嘛,不输出那找到了也看不到。不过windows下写c或者c++真的很难受,就是感觉慢,linux ...
https://bbs.deepin.org/post/149735
输出可以放在计时结束以后呀。
另外我在 deepin 上找 100000 用了 39 秒(去掉输出),所以有点怀疑你的 ...

https://bbs.deepin.org/post/149735
我的cpu是core i7-4702HQ 2.2GHz,应该是i7里面最烂的了。现在i9都出了,你i5可以换了 ...
https://bbs.deepin.org/post/149735
你这个U最大频率 3.2,应该不至于比我的快那么多吧,你再确认一下 100000 没写错?
电脑是公司配的,不坏 ...
https://bbs.deepin.org/post/149735
是的,100000个(没有去掉输出),最后一个数大概是130-0000左右。
https://bbs.deepin.org/post/149735
好奇,能把你编译出来的程序发一下吗?这个是我的
https://bbs.deepin.org/post/149735
好奇,能把你编译出来的程序发一下吗?这个是我的
Popular Ranking
ChangePopular Events
More
我之后用visual studio的release模式便宜了一下,跑的比乌龟还慢。。。。。。
哪位大神能指点一下?完全搞不懂。。。。。
##################代码部分########################################
#include
#include
#include
using namespace std::chrono;
using namespace std;
int get_prime(vector& vec, int num){
for(auto i : vec){
if (num%i==0){
return 0;
}
}
return num;
}
void prime(int n){
vector vec;
cout << "prime number found -> 2\n";
int k = 2;
int num = 3;
while(k < n){
auto result = get_prime(vec, num);
if(result != 0){
cout << "prime number found -> " << result << "\n";
vec.push_back(result);
++k;
}
++num;
}
}
int main(int argc, char** argv){
auto t1 = high_resolution_clock::now();
prime(atoi(argv[1]));
auto t2 = high_resolution_clock::now();
cout <<"It costs "<< duration_cast(t2-t1).count() <<" milliseconds" << endl;
return 0;
}