PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > vector vs map iterator
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
vector vs map iterator

Réponse
 
LinkBack Outils de la discussion
Vieux 02/07/2008, 14h31   #1
xyz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut vector vs map iterator

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
  Réponse avec citation
Vieux 02/07/2008, 14h48   #2
AnonMail2005@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector vs map iterator

On Jul 2, 9:31am, xyz <lavanyaredd...@gmail.com> wrote:
> 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
  Réponse avec citation
Vieux 02/07/2008, 14h49   #3
Joe Greer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector vs map iterator

xyz <lavanyareddy.p@gmail.com> wrote in news:fb7c6ce6-5af3-4e24-8a0b-
dc4940bbfcca@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
  Réponse avec citation
Vieux 02/07/2008, 14h50   #4
Joe Greer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector vs map iterator

Joe Greer <jgreer@doubletake.com> wrote in
news:Xns9ACF63DE02FB0jgreerdoubletakecom@85.214.90 .236:

> xyz <lavanyareddy.p@gmail.com> wrote in news:fb7c6ce6-5af3-4e24-8a0b-
> dc4940bbfcca@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
  Réponse avec citation
Vieux 02/07/2008, 14h53   #5
xyz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector vs map iterator

On Jul 2, 3:49pm, Joe Greer <jgr...@doubletake.com> wrote:
> xyz <lavanyaredd...@gmail.com> wrote in news:fb7c6ce6-5af3-4e24-8a0b-
> dc4940bbf...@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 alsohave
> 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 thingto
> consider is that maps, sets, and lists have more overhead per object. With
> 116M objects, that can add up.
>
> HTH,
> joe


for example i am doing the operation as below in my program
whenever i receive a packet or something ...i will check does it
contain in my vector list....
so if I contain around 2 million entreis in my vector and i received
around 100 packets...
then the computation would be 100 packets * 2 million iterations...

as my list goes on incresing I will have more iterations..
this is the problem i am facing with my simulation..
  Réponse avec citation
Vieux 02/07/2008, 14h57   #6
xyz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector vs map iterator

On Jul 2, 3:50pm, Joe Greer <jgr...@doubletake.com> wrote:
> Joe Greer <jgr...@doubletake.com> wrote innews:Xns9ACF63DE02FB0jgreerdoubletakecom@85.214. 90.236:
>
>
>
> > xyz <lavanyaredd...@gmail.com> wrote in news:fb7c6ce6-5af3-4e24-8a0b-
> > dc4940bbf...@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


I have already used the profiler to know the time consuming places in
my program....
I checked smaller protion of my 7gb file...which showed the time
consuming part is at what i mentioned
  Réponse avec citation
Vieux 02/07/2008, 14h58   #7
Juha Nieminen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector vs map iterator

xyz wrote:
> 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....


It's not a question of iterators. It's a question of what is it that
you are doing with your vector/map and how you are using those iterators.

(And no, when measured in clock cycles, no operation done to a map
iterator is faster than to a vector iterator. On the contrary. However,
I have the feeling you are not really talking about the iterators
per se.)
  Réponse avec citation
Vieux 02/07/2008, 15h10   #8
Jim Langston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector vs map iterator

"xyz" <lavanyareddy.p@gmail.com> wrote in message
news:fb7c6ce6-5af3-4e24-8a0b-dc4940bbfcca@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


Performance for what? Insertions? Deletions? Insertions in middle? End?
Beginning? Deletion is middle? End? Beginning? Lookups in beginning?
End? Middle?

Different containers (vector, set, map, etc...) are designed for different
tasks and each has it's power and it's weakness.

Maybe this link will : http://www.linuxsoftware.co.nz/cppcontainers.html
maybe it won't. Check the bottom anyway to determine which container to
chose.

Also, the wiki has a little bit about the speed of some of the containers:
http://en.wikipedia.org/wiki/Standard_Template_Library

Really, without knowing what you are trying to optmize it is hard to say.

std::vector<MyClass> MyVector;
/*... */
MyVector[SomeCounter]
should be a relatively fast operation, very similar to pointer math.

std::map<Mykey, MyClass> MyMap;
/* ... */
MyMap.find( SomeKey );
is a binary search lookup.
MyMap[SomeKey]
is also a binary key lookup, with the additon of possibly adding the key and
data.

Without knowing how you are using the vector it is hard to say. One thing I
would hope, however is that you are preallocating enough memory for your
vector so that it doesn't have to keep newing when it runs out of memory.

I have no idea why your operation is taking 2 days, maybe it should be.
Maybe it shouldn't. :But without knowing more about what you are actually
doing anything we come up with is a shot in the dark.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h48.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15065 seconds with 16 queries