normalized signature of signals/slots

Olivier Goffart <[email protected]> Sat, 12 Nov 2005 11:30:50 +0100
Newsgroups gmane.comp.kde.devel.optimize
Message-ID <[email protected]>
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 ?

_______________________________________________
Kde-optimize mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-optimize
test_signals.cpp (text/x-c++src, 1.9 KB)
#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, 280 B)
#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
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQBDdcRhz58lY8jWrL0RAljkAJ40Q3YBK++zvHrz6DOqt0CvFuANxACeLljM
pJIDMt+elGKb/fXsgOzTJNI=
=FtNZ
-----END PGP SIGNATURE-----