[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: kdelibs/kfile
From: Hans Petter Bieker <zerium () traad ! lavvu ! no>
Date: 1999-06-23 18:20:17
[Download RAW message or body]
On Wed, 23 Jun 1999, Stephan Kulow wrote:
> That's the problem with using QString. If you want to compare the
> first couple of characters, you have to create a complete new
> string and you make it way slower ;(
#include <qstring.h>
int main()
{
QString a1("hei på deg");
QString a2("hei på meg");
int i;
for (i = 0; i < 6400000; i++)
strcmp(a1.latin1(), a2.latin1());
}
...takes:
real 0m8.410s
user 0m8.211s
sys 0m0.067s
If I change "strcmp(a1.latin1(), a2.latin1());" to a1.compare(a2); or just
a1 == a2, it the results are:
real 0m22.573s
user 0m21.889s
sys 0m0.090s
If I change "a1 == a2" to "a1.lower() == a2.lower();", and just test 1/10,
the results are..:
real 0m28.776s
user 0m28.914s
sys 0m0.093s
> Perhaps QString should get far more operators to make this easier,
> for example instead of using qstring1.left(3) == qstring2.left(3)
> there could be qstring1.strncmp(qstring2, 3) or something like that...
Maybe... But why is QString::compare() so much slower than strcmp() in
the first place?
I tried to create my own compare():
bool compare( const QString &as, const QString &bs )
{
if (as.length() != bs.length()) return false;
const QChar *a = as.unicode();
const QChar *b = bs.unicode();
if (memcmp(a, b, as.length() * sizeof(QChar)) != 0)
return false;
return true;
}
That code seems to work, but uses only:
real 0m0.681s
user 0m1.562s
sys 0m0.062s
What am I missing?
> At least now we buy the price of having the possibility of showing
> cjk filenames with speed.
cjk?
-bieker-
Benytt Dem av http://www.excite.no/, det gjør jeg! -- Ich vermisse Kiel!
Oslo, Kongeriket Norge/Norwegiches Königreich/Monarchy of Norway, Europ[ae]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic