
Originally Posted by
stefan
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.
unsigned int diff = 1000000;
t.start();
for(unsigned int i = 0; i < diff; ++i){
usleep(1);
}
qDebug("Time elapsed: %d ms", t.elapsed());
unsigned int diff = 1000000;
QTime t;
t.start();
for(unsigned int i = 0; i < diff; ++i){
usleep(1);
}
qDebug("Time elapsed: %d ms", t.elapsed());
To copy to clipboard, switch view to plain text mode
Execution time: 3894ms
unsigned int diff = 1000000;
t.start();
try{
for(unsigned int i = 0; i < diff; ++i){
usleep(1);
}
}catch(int bla){
(void) bla;
}
qDebug("Time elapsed: %d ms", t.elapsed());
unsigned int diff = 1000000;
QTime t;
t.start();
try{
for(unsigned int i = 0; i < diff; ++i){
usleep(1);
}
}catch(int bla){
(void) bla;
}
qDebug("Time elapsed: %d ms", t.elapsed());
To copy to clipboard, switch view to plain text mode
Execution time: 7708ms
unsigned int diff = 1000000;
t.start();
try{
for(unsigned int i = 0; i < diff; ++i){
usleep(1);
}
}catch(int bla){
(void) bla;
}catch(int bla2){
(void) bla2;
}
qDebug("Time elapsed: %d ms", t.elapsed());
unsigned int diff = 1000000;
QTime t;
t.start();
try{
for(unsigned int i = 0; i < diff; ++i){
usleep(1);
}
}catch(int bla){
(void) bla;
}catch(int bla2){
(void) bla2;
}
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.
Bookmarks