[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-optimize
Subject: normalized signature of signals/slots
From: Olivier Goffart <ogoffart () kde ! org>
Date: 2005-11-12 10:30:50
Message-ID: 200511121130.57257.ogoffart () kde ! org
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
Hello
When browsing the Qt code, i saw that Qt first try to connect signals without
normalize the signature, and if it fails, it normalize the slot signature and
retry .
So using normalized signature in signal slot connection is faster that don't
But how much, maybe that's negligible ?
After some test (attached) I noticed that the normalized signature is about
twice times faster than the not normalized one
(This may i guess be even more in the case of bigger signatures, or class with
more signals and slots)
Usually, we don't use normalized signature: Less intuitive, and the one
KDevelop auto-complete (nice feature btw) is not normalized.
Does it make sens to write a script that normalize signatures in the code ?
["test_signals.cpp" (text/x-c++src)]
#include "test_signals.h"
#include <QDateTime>
#include <iostream>
void Test::someSlot(const QString&,const QString&) {};
int main()
{
int normalized_time;
int cu_time;
QTime ti;
Test t;
ti.start();
for(int f=0;f<20000;f++)
{
QObject::connect(&t,SIGNAL(someSignal(QString,QString)) , &t, \
SLOT(someSlot(QString,QString))); \
QObject::disconnect(&t,SIGNAL(someSignal(QString,QString)) , &t, \
SLOT(someSlot(QString,QString))); \
QObject::connect(&t,SIGNAL(someSignal(QString,QString)) , &t, \
SLOT(someSlot(QString,QString))); \
QObject::disconnect(&t,SIGNAL(someSignal(QString,QString)) , &t, \
SLOT(someSlot(QString,QString))); \
QObject::connect(&t,SIGNAL(someSignal(QString,QString)) , &t, \
SLOT(someSlot(QString,QString))); \
QObject::disconnect(&t,SIGNAL(someSignal(QString,QString)) , &t, \
SLOT(someSlot(QString,QString))); }
normalized_time=ti.elapsed();
std::cout << "normalized: " << normalized_time << "ms\n";
ti.start();
for(int f=0;f<20000;f++)
{
QObject::connect(&t,SIGNAL(someSignal(const QString&, const QString&)) , &t, \
SLOT(someSlot(const QString&, const QString&))); \
QObject::disconnect(&t,SIGNAL(someSignal(const QString&, const QString&)) , &t, \
SLOT(someSlot(const QString&, const QString&))); \
QObject::connect(&t,SIGNAL(someSignal(const QString&, const QString&)) , &t, \
SLOT(someSlot(const QString&, const QString&))); \
QObject::disconnect(&t,SIGNAL(someSignal(const QString&, const QString&)) , &t, \
SLOT(someSlot(const QString&, const QString&))); \
QObject::connect(&t,SIGNAL(someSignal(const QString&, const QString&)) , &t, \
SLOT(someSlot(const QString&, const QString&))); \
QObject::disconnect(&t,SIGNAL(someSignal(const QString&, const QString&)) , &t, \
SLOT(someSlot(const QString&, const QString&))); }
cu_time=ti.elapsed();
std::cout << "usual: " << cu_time << "ms ratio: "<< \
(double)cu_time/(double)normalized_time <<"\n";
return 1;
}
#include "test_signals.moc"
["test_signals.h" (text/x-c++hdr)]
#ifndef TTTTT
#define TTTTT
#include <QObject>
#include <QString>
class Test : public QObject
{ Q_OBJECT
public slots:
#ifndef SALUT
void someSlot(const QString& str, const QString &str2);
signals:
void someSignal(const QString& str, const QString &str2);
#endif
};
#endif
[Attachment #9 (application/pgp-signature)]
_______________________________________________
Kde-optimize mailing list
Kde-optimize@kde.org
https://mail.kde.org/mailman/listinfo/kde-optimize
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic