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

_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to