--===============0177206180== Content-Type: multipart/signed; boundary="nextPart4242209.PabFRKPqpg"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart4242209.PabFRKPqpg Content-Type: multipart/mixed; boundary="Boundary-01=_3FcdDXAUNs7tj/6" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_3FcdDXAUNs7tj/6 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello. When browsing the kdelibs code, i seen sometimes in the code few qobject_ca= st=20 when i would used dynamic_cast So my question was, what's the difference between qobject_cast and=20 dynamic_cast ? After having doing some test, it seems that qobject_cast is 3 times faster= =20 than dynamic_cast. So I'll change my habit, and use qobject_cast instead of dynamic_cast when= =20 casting objects. Of course, I must continue to use static_cast which is still 10 times faste= r=20 than qobject_cast when i know what my object is. The attached test, compiled with -O2 no cast: 11 ms static_cast: 19ms ratio: 1.72727 dynamic_cast: 872ms ratio: 79.2727 qobject_cast: 290ms ratio: 26.3636 dynamic ratio :3.0069 note that when i compile with -O0 , static_cast is faster than no cast,=20 strange. --Boundary-01=_3FcdDXAUNs7tj/6 Content-Type: text/x-c++src; charset="us-ascii"; name="test_cast.cpp" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="test_cast.cpp" #include "test_cast.h" #include #include int main() { QTime ti; int cu_ti; Test T; T.i=3D0; T.j=3D0; Test *t=3D&T; QObject *o=3D&T; ti.start(); do { t->i++; t->j++; } while(t->i<8000000); int base=3Dti.elapsed(); std::cout << "no cast: " << base << " ms\n"; T.i=3D0; ti.start(); do { static_cast(o) ->i++; static_cast(o) ->j++; } while(static_cast(o)->i < 8000000); cu_ti=3Dti.elapsed(); std::cout << "static_cast: " << cu_ti << "ms ratio: " << (double)cu_ti/(= double)base << "\n"; =09 T.i=3D0; ti.start(); do { dynamic_cast(o) ->i++; dynamic_cast(o) ->j++; } while(dynamic_cast(o)->i < 8000000); cu_ti=3Dti.elapsed(); std::cout << "dynamic_cast: " << cu_ti << "ms ratio: " << (double)cu_ti/= (double)base << "\n"; =09 T.i=3D0; ti.start(); do { qobject_cast(o) ->i++; qobject_cast(o) ->j++; } while(qobject_cast(o)->i < 8000000); int qo_ti=3Dti.elapsed(); std::cout << "qobject_cast: " << qo_ti << "ms ratio: " << (double)qo_ti/= (double)base << " dynamic ratio :" << (double)cu_ti/(double)qo_ti << "\n= "; =09 return 1; } #include "test_cast.moc" --Boundary-01=_3FcdDXAUNs7tj/6 Content-Type: text/x-c++hdr; charset="us-ascii"; name="test_cast.h" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="test_cast.h" #ifndef TTTTT #define TTTTT #include #include class Test : public QObject { Q_OBJECT public: int i; int j; int h; }; #endif --Boundary-01=_3FcdDXAUNs7tj/6-- --nextPart4242209.PabFRKPqpg Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQBDdcF9z58lY8jWrL0RAuJ9AJ9gz9iBpP9bhcOB+TtaHHE644+dMACcCrz8 DDYT3gYlppeT9aB6hK/Sc88= =RJpG -----END PGP SIGNATURE----- --nextPart4242209.PabFRKPqpg-- --===============0177206180== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kde-optimize mailing list Kde-optimize@kde.org https://mail.kde.org/mailman/listinfo/kde-optimize --===============0177206180==--