making multiset destructor faster...

This is a discussion on making multiset destructor faster... within the C++ Programming forums, part of the General Programming Boards category; Code: void test() { clock_t t1 = clock(); std::multiset<int> set; for (int i = 0; i < 1000000; ++i) set.insert(i); ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    188

    making multiset destructor faster...

    Code:
    void test()
    {
    	clock_t t1 = clock();
    	std::multiset<int> set;
    	for (int i = 0; i < 1000000; ++i)
    		set.insert(i);
    
    	clock_t t2 = clock();
    	cout << "time: " << t2 - t1 << "ms" << endl;
    }
    on my machine, with optimizations turned on, an e8400 overclocked to 3.6ghz that takes 1357ms to do all the insertions. the time for the function to exit is 105813ms, which means it's taking 104456ms for the destructor of the multiset to run.

    i'm not sure why it's so slow....even if you remove every item 1 by 1 it should still be O(n log n) right? same as insertion?

    is there a way where i can make the cleanup faster?

    thanks.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    There must be something wrong. For me insertions take 1812 ms and total running time of the function is 2156 ms.

    And I don't think the order in which items are removed has to be the same they were inserted, so the destructor should be pretty much linear.
    Last edited by anon; 08-30-2008 at 12:54 PM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    note to self: don't use the debugger for such things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  3. multiset and classes
    By quizkiwi in forum C++ Programming
    Replies: 10
    Last Post: 08-30-2004, 07:08 PM
  4. Replies: 2
    Last Post: 01-13-2003, 01:28 PM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21