[haiku-appserver] Re: performance considerations

  • From: André Braga <meianoite@xxxxxxxxx>
  • To: haiku-appserver@xxxxxxxxxxxxx
  • Date: Mon, 19 Sep 2005 23:09:39 -0300

Not that my opinion counts at all, but as a computer science student
eager to participate in the Haiku project as someone which is not just
a user (as soon as time constraints allow me in), I'd say that I'm all
for simple optimizations as long as they're documented.

I've been very successful with the "sure path/fast path" approach to
optimization, much like the way you did in the code below. As long as
both are kept in the code listing and proper testing is done to show
there are no undesirable side effects, go for it :)



-- 
"A year spent in artificial intelligence is enough to make one believe in God"
-Alan J. Perlis


2005/9/19, Adi Oanca <adioanca@xxxxxxxxx>:
> Hi guys,
> 
> 
>         I know that what you have to say about this, but I wanted to touch 
> this
> subject for a very long time.
> 
>         I think that some aspects of optimizations should be taken into 
> account
> from early times like the beginnings. Others should be left when near
> the release of a product.
> 
>         There are some simple optimizations that we can make now and not let
> them wait for the release date.
> 
>         For example, take the following piece of code:
> #include <OS.h>
> #include <List.h>
> #include <stdio.h>
> 
> int main()
> {
>         bigtime_t t1, t2;
>         BList list;
>         uint8 *ptr = NULL;
> 
>         for (int32 i = 0; i < 30000000; i++) {
>                 list.AddItem(ptr);
>                 ptr++;
>         }
> 
>         int32 i, count = list.CountItems();
>         int32 dummy = 0;
> /*
>         // v1
>         t1 = real_time_clock_usecs();
>         for(i = 0; i < count; i++) {
>                 dummy += (uint32)list.ItemAt(i) %2;
>         }
>         // v1 end
> */
> 
>         // v2
>         uint8 **ptrItems = (uint8**)list.Items();
>         t1 = real_time_clock_usecs();
>         for(i = 0; i < count; i++) {
>                 dummy += (uint32)ptrItems[i] %2;
>         }
>         // v2 end
> 
>         t2 = real_time_clock_usecs();
>         printf("Elapsed %lld. Dummy: %ld\n", t2-t1, dummy);
> }
> 
> when running this code with "v1" and "v2", the following results emerge:
> $ ./BeApp
> Elapsed 268957. Dummy: 15000000
> $ ./BeApp
> Elapsed 266599. Dummy: 15000000
> $ ./BeApp
> Elapsed 265362. Dummy: 15000000
> $ ./BeApp
> Elapsed 264806. Dummy: 15000000
> $ ./BeApp
> Elapsed 51959. Dummy: 15000000
> $ ./BeApp
> Elapsed 49155. Dummy: 15000000
> $ ./BeApp
> Elapsed 49847. Dummy: 15000000
> $ ./BeApp
> Elapsed 49044. Dummy: 15000000
> 
> 500% slowdown in the first case, which is used a lot more often in our code.
> 
> Couldn't we optimize the code when first writing it?
> 
> 
> 
> Thanks,
> Adi.
> 
>

Other related posts: