help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

perfomance of clear vs swap


From: krishanu . debnath
Subject: perfomance of clear vs swap
Date: 28 Nov 2006 11:07:37 -0800
User-agent: G2/1.0

Hello,

I have a call to hash_map::clear() function which takes long time.

someClass::someFunction()
{

    // typedef hash_map<name_id, uint> Mp;
    // Mp p;
    // assuming proper namespace, hash function for name_id obj.

    p.clear();
}

Above p.clear() takes long time, profiling indicates 'number of bucket
of hash table is large'.

Now, just for sake of experiments, I replaced this 'clear' call with
swap. i.e.

someClass::someFunction()
{

    // typedef hash_map<name_id, uint> Mp;
    // Mp p;
    // assuming proper namespace, hash function for name_is obj.

    //p.clear();
    Mp tmp;
    p.swap(tmp);
}

Now runtime drops significantly, 10 fold less.

What's exactly cause this run time reduction? I am using g++ 4.0.2.

Thanks,
Krishanu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]