Results 1 to 11 of 11

Thread: exception catching speed

  1. #1
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default exception catching speed

    hi,
    since i implemented exception catching in my code, it executes about 50% longer than before. Since it's numerical calculation that runs for couple of hours, speed is quite important. number of try-catch blocks is less than 10.

    how much exception catching affects on speed?

  2. #2
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: exception catching speed

    Quote Originally Posted by stefan View Post
    hi,
    since i implemented exception catching in my code, it executes about 50% longer than before. Since it's numerical calculation that runs for couple of hours, speed is quite important. number of try-catch blocks is less than 10.

    how much exception catching affects on speed?
    What are you doing? A quick google search revealed that an unused try/catch block has a performance impact, but only a very little one. If your code regularly throws an exception, consider a redesign. Exceptions are not to be used to control the normal program flow.

  3. #3
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception catching speed

    Quote Originally Posted by Kumosan View Post
    What are you doing? A quick google search revealed that an unused try/catch block has a performance impact, but only a very little one. If your code regularly throws an exception, consider a redesign. Exceptions are not to be used to control the normal program flow.
    im using external solver (program) with whom i comunicate trough ascii files. execution of solver is called about 5 times in a second for couple of hours. since i'm working with files, it's good to catch exceptions, isn't it?

    whats about dividing one try-catch to more of them?

  4. #4
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception catching speed

    i forgot to mention that exception are rarely thrown. maybe couple of times during one day analysis. since we implemented catching, a one hour analysis now lasts around one houre and forty minutes.

  5. #5
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: exception catching speed

    Quote Originally Posted by stefan View Post
    im using external solver (program) with whom i comunicate trough ascii files. execution of solver is called about 5 times in a second for couple of hours. since i'm working with files, it's good to catch exceptions, isn't it?
    5 times/sec? You should not even be able to notice the impact of an unused try/catch block in that case.

    Quote Originally Posted by stefan View Post
    whats about dividing one try-catch to more of them?
    I really doubt your problem is because of an unused try/catch block. But if it is, having more would only increase your problem.

    I'd say now is a good time to fire up your profiler.

  6. #6
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception catching speed

    Quote Originally Posted by Kumosan View Post
    5 times/sec? You should not even be able to notice the impact of an unused try/catch block in that case.
    i don't notice slowdown on one or even on 10 runs o external program (its less than a second)

    but when i run a hounderd thousands of runs (= about 5 hours without catching) it is running for more then seven hours!

  7. #7
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: exception catching speed

    I have not found a pure c++ example. Mostly C# or like in this example gcj:
    http://gcc.gnu.org/ml/java/2004-08/msg00036.html

    You see here with 10,000,000 calls in a for loop it makes a noticeable difference. But still in the range of seconds. I really doubt (but do not actually know) that it is different for pure C++ regardless of what compiler you use.

    Your problem must be somewhere else. After work I'll write a small test program myself. The question somewhat interests me.

  8. The following user says thank you to Kumosan for this useful post:

    stefan (24th October 2008)

  9. #8
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception catching speed

    thank you for your time.
    i doubt that i done some change to the code that is influencing on speed so much. all i did during last days is exception catching..

  10. #9
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception catching speed

    i found a accidentally pause in my code i put it there to test catching of exceptions, so we can blame catching of exceptions for slowdown

  11. #10
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: exception catching speed

    Quote Originally Posted by stefan View Post
    i found a accidentally pause in my code i put it there to test catching of exceptions, so we can blame catching of exceptions for slowdown
    Great. Nevertheless, I did some experiments and my 'findings' are a bit surprising.
    Qt Code:
    1. unsigned int diff = 1000000;
    2. t.start();
    3. for(unsigned int i = 0; i < diff; ++i){
    4. usleep(1);
    5. }
    6. qDebug("Time elapsed: %d ms", t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    Execution time: 3894ms

    Qt Code:
    1. unsigned int diff = 1000000;
    2. t.start();
    3. try{
    4. for(unsigned int i = 0; i < diff; ++i){
    5. usleep(1);
    6. }
    7. }catch(int bla){
    8. (void) bla;
    9. }
    10. qDebug("Time elapsed: %d ms", t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    Execution time: 7708ms

    Qt Code:
    1. unsigned int diff = 1000000;
    2. t.start();
    3. try{
    4. for(unsigned int i = 0; i < diff; ++i){
    5. usleep(1);
    6. }
    7. }catch(int bla){
    8. (void) bla;
    9. }catch(int bla2){
    10. (void) bla2;
    11. }
    12.  
    13. qDebug("Time elapsed: %d ms", t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    Execution time: 7743ms

    So the try/catch block has a noticeable influence on speed, but
    it looks like the effect of a second catch is in most cases negligible.

  12. The following user says thank you to Kumosan for this useful post:

    stefan (12th November 2008)

  13. #11
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception catching speed

    Quote Originally Posted by Kumosan View Post
    Great. Nevertheless, I did some experiments and my 'findings' are a bit surprising.
    Qt Code:
    1. unsigned int diff = 1000000;
    2. t.start();
    3. for(unsigned int i = 0; i < diff; ++i){
    4. usleep(1);
    5. }
    6. qDebug("Time elapsed: %d ms", t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    Execution time: 3894ms

    Qt Code:
    1. unsigned int diff = 1000000;
    2. t.start();
    3. try{
    4. for(unsigned int i = 0; i < diff; ++i){
    5. usleep(1);
    6. }
    7. }catch(int bla){
    8. (void) bla;
    9. }
    10. qDebug("Time elapsed: %d ms", t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    Execution time: 7708ms

    Qt Code:
    1. unsigned int diff = 1000000;
    2. t.start();
    3. try{
    4. for(unsigned int i = 0; i < diff; ++i){
    5. usleep(1);
    6. }
    7. }catch(int bla){
    8. (void) bla;
    9. }catch(int bla2){
    10. (void) bla2;
    11. }
    12.  
    13. qDebug("Time elapsed: %d ms", t.elapsed());
    To copy to clipboard, switch view to plain text mode 

    Execution time: 7743ms

    So the try/catch block has a noticeable influence on speed, but
    it looks like the effect of a second catch is in most cases negligible.
    thanks, very simple benchmark, but results are very interesting.
    i suppose nested try blocks are even more slower..

Similar Threads

  1. Exceptions and qApp->processEvents()
    By mcostalba in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2006, 17:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.