矢量vs地图迭代器 [英] vector vs map iterator

查看:73
本文介绍了矢量vs地图迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须运行跟踪文件的模拟(7gb包含

1.16亿条目)...

目前我正在使用矢量迭代器来检查条件我的

计划.....

需要2天才能完成整个模拟.....


my问题是地图迭代器比矢量更快

迭代器.....

它是否提高了性能....

感谢所有

解决方案

7月2日,9:31 * am,xyz< lavanyaredd ... @ gmail.comwrote:


我必须运行跟踪文件的模拟(7gb包含

1.16亿条目)...

目前我正在使用矢量迭代器来检查我的

程序中的条件.....

它需要2天才能完成整个模拟.....


我的问题是地图迭代器比矢量更快

迭代器.....

是否改善了t他的表现....

感谢所有



因为一个向量被保证成为连续的内存,所以它是iterator

*可以在内部实现为指针 - 速度很快。一个

的地图是列表式的,因为它有节点所以它的迭代器会有一个取消引用一个指针 - 这是慢一点的
。所以,在非常一般的

术语中,我认为地图迭代器会更慢。


但是...


使用一个好的分析器来确定你的程序的哪些部分是耗时的。没有探查器,你只是猜测。


HTH


xyz< la ******* *****@gmail.com在新闻中写道:fb7c6ce6-5af3-4e24-8a0b-
dc**********@25g2000hsx.googlegroups.com


我必须运行跟踪文件的模拟( 7gb包含

1.16亿条目)...

目前我正在使用矢量迭代器检查我的

程序中的条件.....

完成整个模拟需要2天.....


我的问题是地图迭代器比矢量更快

iterators .....

它是否提高了性能....

感谢所有



我不确定你在迭代器上执行了什么操作,但是

矢量迭代器的速度和你一样快。地图通常是一棵树

某种类型的结构,从一个节点移动到下一个节点通常需要从内存中加载一个值,而使用向量,它只会

从迭代器中已有的地址加上或减去一个固定的数量。

这往往更快。同样的事情适用于列表。矢量也有更好的参考位置,因此当读取一个项目时,整个页面会进入内存并且你可以免费获得目标周围的物体。地图,

集,列表等如果他们的语义符合你想要做的更好

更好。也就是说,如果你发现自己经常搜索对象,那么

地图和集合就更自然了。尽管如此,使用二进制搜索算法对矢量和

进行排序可能会表现得更好。

考虑的另一件事是地图,集合和列表每个对象的开销更大。使用

116M对象,可以加起来。


HTH,

joe


Joe Greer< jg **** @ doubletake.comwrote in

新闻:Xn ******************** *************@85.214.90 .236:


xyz< la ********** **@gmail.com在新闻中写道:fb7c6ce6-5af3-4e24-8a0b-
dc ** ********@25g2000hsx.googlegroups.com


>我必须运行跟踪文件的模拟(7gb)包含
1.16亿条目)...
目前我正在使用矢量迭代器检查我的
程序中的条件.....
需要2天才能完成整个模拟.....
我的问题是地图迭代器比矢量
迭代器更快.....
它是否提高了性能....
感谢所有



我不确定您在itera上执行的操作tw,

但是矢量迭代器的速度和你一样快。地图通常是某种类型的树形结构并从一个节点移动到另一个节点

通常需要从内存中加载一个值而使用

向量,它只是在迭代器中已经从地址

中添加或减去固定数量。这往往更快。同样的事情适用于列表中的
。向量也有更好的引用位置,因此当读取

项时,整个页面进入内存,你可以免费获得围绕目标的对象
。地图,集合,列表等更好,如果它们的语义与你想要做的更好。也就是说,如果你发现自己经常搜索对象,那么地图和集合就更自然了。尽管如此,对矢量进行排序并使用二进制

搜索算法可能会表现得更好。要考虑的另一件事是

,映射,集合和列表每个对象有更多的开销。有了116M

的物品,可以加起来。


HTH,

joe



我同意评论使用剖析器确保你是优化正确的东西。


joe


I have to run the simulation of a trace file around (7gb contains
116million entries)...
presently i am using vector iterators to check the conditions in my
program.....
it is taking 2 days to finish whole simulation.....

my question are the map iterators are faster than vector
iterators.....
does it improve the performance....
thanks to all

解决方案

On Jul 2, 9:31*am, xyz <lavanyaredd...@gmail.comwrote:

I have to run the simulation of a trace file around (7gb contains
116million entries)...
presently i am using vector iterators to check the conditions in my
program.....
it is taking 2 days to finish whole simulation.....

my question are the map iterators are faster than vector
iterators.....
does it improve the performance....
thanks to all

Since a vector is guarenteed to be contiguous memory, it''s iterator
*could* be implemented internally as a pointer - which is fast. A
map is list-like in that is has nodes so it''s iterator would have
to dereference a pointer - which is slower. So, in very general
terms, I think maps iterators would be slower.

But...

Use a good profiler to determine which parts of your program are
time consuming. Without a profiler, you''re just guessing.

HTH


xyz <la************@gmail.comwrote in news:fb7c6ce6-5af3-4e24-8a0b-
dc**********@25g2000hsx.googlegroups.com:

I have to run the simulation of a trace file around (7gb contains
116million entries)...
presently i am using vector iterators to check the conditions in my
program.....
it is taking 2 days to finish whole simulation.....

my question are the map iterators are faster than vector
iterators.....
does it improve the performance....
thanks to all

I am not sure what operations you are performing on your iterators, but
vector iterators are about as fast as you get. Maps are generally a tree
structure of some sort and moving from one node to the next will generally
require loading a value from memory whereas with a vector, it will simply
add or subtract a fixed amount from the address already in the iterator.
This tends to be faster. Same thing applies to a list. Vectors also have
better locality of reference so when an item is read, the whole page comes
into memory and you get the objects surrounding the target for free. maps,
sets, lists etc are better if their semantics match what you want to do
better. That is, if you find yourself searching for objects a lot, then
maps and sets are more natural. Though even then, sorting the vector and
using the binary search algorithms may perform better. The other thing to
consider is that maps, sets, and lists have more overhead per object. With
116M objects, that can add up.

HTH,
joe


Joe Greer <jg****@doubletake.comwrote in
news:Xn*********************************@85.214.90 .236:

xyz <la************@gmail.comwrote in news:fb7c6ce6-5af3-4e24-8a0b-
dc**********@25g2000hsx.googlegroups.com:

>I have to run the simulation of a trace file around (7gb contains
116million entries)...
presently i am using vector iterators to check the conditions in my
program.....
it is taking 2 days to finish whole simulation.....

my question are the map iterators are faster than vector
iterators.....
does it improve the performance....
thanks to all


I am not sure what operations you are performing on your iterators,
but vector iterators are about as fast as you get. Maps are generally
a tree structure of some sort and moving from one node to the next
will generally require loading a value from memory whereas with a
vector, it will simply add or subtract a fixed amount from the address
already in the iterator. This tends to be faster. Same thing applies
to a list. Vectors also have better locality of reference so when an
item is read, the whole page comes into memory and you get the objects
surrounding the target for free. maps, sets, lists etc are better if
their semantics match what you want to do better. That is, if you
find yourself searching for objects a lot, then maps and sets are more
natural. Though even then, sorting the vector and using the binary
search algorithms may perform better. The other thing to consider is
that maps, sets, and lists have more overhead per object. With 116M
objects, that can add up.

HTH,
joe

I also agree with the comment to use a profiler to be sure you are
optimizing the proper thing.

joe


这篇关于矢量vs地图迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆