[haiku-appserver] performance considerations

  • From: Adi Oanca <adioanca@xxxxxxxxx>
  • To: haiku-appserver@xxxxxxxxxxxxx
  • Date: Tue, 20 Sep 2005 02:12:47 +0300

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: