boost::push_back相关的测试程序

161 篇文章 ¥59.90 ¥99.00
本文介绍了一个关于boost::push_front的测试程序,通过对比std::容器与boost::容器在push_front操作上的性能,展示了在大量元素情况下,boost::push_front能提升程序效率。

boost::push_back相关的测试程序

在C++中,容器类是非常重要的数据结构,常用的STL容器有vector、list、deque等。其中,vector是基于连续内存空间的动态数组,push_back操作常被使用。而对于像list这样的双向链表容器,除了push_back还有push_front操作。而boost库则提供了一个可用于各种容器的操作——push_front。

为了测试boost::push_front操作的性能和正确性,我们可以编写如下代码:

#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <string>
#include <chrono>
#include <boost/container/vector.hpp>
#include <boost/container/list.hpp>
#include <boost/container/deque.hpp>

template<typename T>
void test_push_front(const std::string& name, const size_t size) {
  std::cout << "Testing " << name << " with size = " << size << std::endl;

  // Standard container
 
void DataSDMap::parse_graph(OsmGraph const &sdMap, Eigen::Affine3d const &transformationMatrix, std::vector<EdgeInfo> &edges_info, bool crop) const noexcept { // get roi corner points std::vector<Point> canvas_polygon; if (crop) { double min_x = -1 * roiLength; double max_x = roiLength; double min_y = -1 * roiWidth; double max_y = roiWidth; canvas_polygon.push_back(Point(min_x, min_y)); canvas_polygon.push_back(Point(min_x, max_y)); canvas_polygon.push_back(Point(max_x, max_y)); canvas_polygon.push_back(Point(max_x, min_y)); } auto start = std::chrono::high_resolution_clock::now(); edges_info.clear(); // 读取graph中的edges数据,还原edge geometry // std::cout << "Number of edges: " << boost::num_edges(sdMap) << std::endl; std::pair<boost::adjacency_list<>::vertex_iterator, boost::adjacency_list<>::vertex_iterator> vertices_pair = boost::vertices(sdMap); // boost::iterator_range<boost::graph_traits<OsmGraph>::vertex_iterator> // vertices_pair = boost::make_iterator_range(vertices(sdMap)); for (auto e : // boost::make_iterator_range(boost::edges(sdMap))) for (auto e = boost::edges(sdMap).first; e != boost::edges(sdMap).second; ++e) { const OsmEdgeProperties &edgeProps = sdMap[*e]; // get vertices geometry LineString linestring_global; std::string line_geometry_string = edgeProps.geometry; if (line_geometry_string.empty()) { boost::adjacency_list<>::vertex_descriptor source = boost::source(*e, sdMap); boost::adjacency_list<>::vertex_descriptor target = boost::target(*e, sdMap); if (source == target) continue; line_geometry_string = "LINESTRING ("; const OsmNodeProperties &startNodeProps = sdMap[*(vertices_pair.first + source)]; line_geometry_string = line_geometry_string + startNodeProps.x + " " + startNodeProps.y + ", "; const OsmNodeProperties &endNodeProps = sdMap[*(vertices_pair.first + target)]; line_geometry_string = line_geometry_string + " " + endNodeProps.x + " " + endNodeProps.y + ")"; } boost::geometry::read_wkt(line_geometry_string, linestring_global); auto end = std::chrono::high_resolution_clock::now(); auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); 分析这段代码在周期性调用时,运行时间在递增,分析可能的原因?
06-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值