小编use*_*461的帖子

为什么我的swap <string,string>比std版本慢得多?

这是我的C++代码:

inline static void swap(std::string& a1, std::string& a2) {    
    std::string temp( std::move(a1));
    a1 = std::move( a2 );
    a2 = std::move( temp );
}
Run Code Online (Sandbox Code Playgroud)

我运行了这个功能1000000次,平均花了78ms,但是这只std花了13ms.我只是看了一下实现std::swap,我发现它跟我的一样,所以为什么我的这么慢?

c++ performance c++11

6
推荐指数
1
解决办法
297
查看次数

标签 统计

c++ ×1

c++11 ×1

performance ×1