|
//thrust与c++的STL进行向量copy时间比较
// c++ STL time(单位是微秒): 4514929
// thrust time: 547
//速度差距还是非常明显的
- #include <thrust/device_vector.h>
- #include <iostream>
- #include <sys/time.h>
- //thrust与c++的STL进行向量copy时间比较
- // c++ STL time(单位是微秒): 4514929
- // thrust time: 547
- //速度差距还是非常明显的
- int main(void){
- thrust::device_vector<int> D(1000000);
- thrust::sequence(D.begin(), D.end());
- std::vector<int> s(1000000);
- // 统计时间
- struct timeval startTime, endTime;
- gettimeofday(&startTime, NULL);
- std::copy(D.begin(), D.end(), s.begin()); // stl的copy方法
- gettimeofday(&endTime, NULL);
- printf("c++ STL time(单位是微秒): %ld\n",
- (endTime.tv_sec - startTime.tv_sec)*1000000 + (endTime.tv_usec - startTime.tv_usec));
- gettimeofday(&startTime, NULL);
- thrust::copy(D.begin(), D.end(), s.begin()); // thrust的copy方法
- gettimeofday(&endTime, NULL);
- printf("thrust time: %ld\n",
- (endTime.tv_sec - startTime.tv_sec)*1000000 + (endTime.tv_usec - startTime.tv_usec));
- return 0;
- }
复制代码
|
|