Re: QCString construction

David Faure <[email protected]> Sat, 10 Feb 2007 12:32:55 +0100
Newsgroups gmane.comp.kde.devel.optimize
Organization Klaralvdalens Datakonsult.
Message-ID <[email protected]>
--Boundary-00=_51azF/SSf9gS5zP
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On Saturday 10 February 2007, David Faure wrote:
> Here's a benchmark I wrote which proves how much we can gain (and it also=
 proves
> that the resulting qcstring is correct ;)
>=20
> Results on amd64 with -g3 and no optimization:
> QCString(char*) took 1582 milliseconds
> QCString(n)+memcpy took 134 milliseconds
> QCString()+setRawData took 31 milliseconds
>=20
> Results on i686 with -O2:
> QCString(char*) took 2558 milliseconds
> QCString(n)+memcpy took 161 milliseconds
> QCString()+setRawData took 35 milliseconds

I forgot to attach the benchmark - in case someone spots an error, or an ev=
en better way to do it.

=2D-=20
David Faure, [email protected], [email protected]
KDE/KOffice developer, Qt consultancy projects
Klar=C3=A4lvdalens Datakonsult AB, Platform-independent software solutions

--Boundary-00=_51azF/SSf9gS5zP
Content-Type: text/x-c++src;
  charset="utf-8";
  name="qcstring_perf.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="qcstring_perf.cpp"

#include <qcstring.h>
#include <stdio.h>
#include <assert.h>
#include <qdatetime.h>

int main()
{
   const int dataLength = 10000;
   char* charData = new char[dataLength];
   for ( uint i = 0; i < dataLength; ++i )
       charData[i] = 'A';
   charData[dataLength-1] = '\0';

   int numIterations = 100000;

   QTime time;
   time.start();

   for ( uint i = 0; i < numIterations; ++i ) {
       QCString cstr = charData;
       assert( cstr[0] == 'A' );
       assert( cstr[dataLength-1] == '\0' );
   }

   int elapsed = time.elapsed();
   qDebug( "QCString(char*) took %i milliseconds", time.elapsed() );

   time.restart();
   for ( uint i = 0; i < numIterations; ++i ) {
       QCString cstr(dataLength);
       memcpy( cstr.data(), charData, dataLength );
       assert( cstr[0] == 'A' );
       assert( cstr[dataLength-1] == '\0' );
   }
   qDebug( "QCString(n)+memcpy took %i milliseconds", time.elapsed() );

   time.restart();
   for ( uint i = 0; i < numIterations; ++i ) {
       QCString cstr;
       cstr.setRawData( charData, dataLength );
       assert( cstr[0] == 'A' );
       assert( cstr[dataLength-1] == '\0' );
       cstr.resetRawData( charData, dataLength );
   }
   qDebug( "QCString()+setRawData took %i milliseconds", time.elapsed() );

   return 0;
}

--Boundary-00=_51azF/SSf9gS5zP
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Kde-optimize mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-optimize

--Boundary-00=_51azF/SSf9gS5zP--