Re: g_strjoinv() is very slow



George wrote:

> On Sun, Sep 24, 2000 at 03:48:19PM -0400, Sean Middleditch wrote:
> > >     OK. Thanks for all your comments.
> > >  I've attached a new version which takes all your remarks in account.
> > >
> >
> > OK, just to point something out, all those for (int i = 1; array[i] != NULL;
> > i++) and whatnot's in the for loops should be something like
> >
> > for (char *c = str + 1; *c != 0; c ++)
> > That way, you don't have to do an index lookup on every iteration... it'll
> > speed the code up a lot (one less multiplication per iteration).
>
> I used to think so too.  But have you done profiling on recent machines?  In
> fact the index is faster.  I would say it has to do with good optimization
> and possibility to do larger prefetch.  With the pointer you can really only
> fetch the value at the dereference time and then have to refetch it.
> Try profiling this, it's quite amazing.
>
> So, no, those shouldn't be changed.  I use the pointer iteration a lot
> because I find it nicer sometimes, but the array index just IS faster.
>

Interesting.  I haven't ran a profiler under Linux at all, but this didn't tend
to be the case on the Windows machines I developed on a year back...

I'll take a look at this.

>
> > That's how functions like these are coded in the various incarnations of
> > libc, too.  Never use an index value to an array when a pointer to the value
> > is usable.  If you need to find the actual index value from the start of an
> > array, you can use (c - str), which is one subtraction per loop, which is
> > still faster than a multiplication.
>
> But you kill nice cache behaviour.  Operations like mutliplication etc... are
> by now fast enough that the bottleneck is the memory fetch.
>

I see.  OK.  I'll keep that in mind.  Thanks!

Sean, Etc.

>
> George
>
> --
> George <jirka 5z com>
>    If God did not exist, it would be necessary to invent him.
>                        -- Voltaire
>
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]