Re: remove BufferBlockPointers for speed and space

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Qingqing Zhou <zhouqq(at)cs(dot)toronto(dot)edu>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: remove BufferBlockPointers for speed and space
Date: 2005-08-11 15:11:59
Message-ID: 42FB6ABF.9060305@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Hello,

With gcc-4 on Ubuntu AMD Athlon 2600 Barton:

jd(at)jd:~$ ./a.out
duration round 1 of array method: 0.539 ms
duration round 2 of array method: 0.529 ms
duration round 3 of array method: 0.530 ms
duration round 1 of mul method: 0.258 ms
duration round 2 of mul method: 5.563 ms
duration round 3 of mul method: 0.258 ms
duration round 1 of shift method: 0.240 ms
duration round 2 of shift method: 0.248 ms
duration round 3 of shift method: 0.240 ms
jd(at)jd:~$

Sincerely,

Joshua D. Drake

Qingqing Zhou wrote:

>"Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>
>
>>Also, I would like to see the actual test code. I wonder whether what
>>you measured is the ability of the compiler to optimize references to
>>successive elements of an array inside a loop; that has little or
>>nothing to do with the typical usage of BufferGetBlock().
>>
>>
>>
>
>The source code is attached.
>
>compiled with "gcc testbuf.c". I tried -O2 actually, and it turns out that
>the timing is reduced a lot so not believable.
>---
>
>/*
> * testbuf.c
> */
>#include <stdio.h>
>#include <sys/file.h>
>#include <sys/param.h>
>#include <sys/stat.h>
>#include <sys/time.h>
>#include <unistd.h>
>#include <fcntl.h>
>
>#define BLCKSZ 8192
>#define NBuffers 80000
>
>typedef void* Block;
>
>int main(void)
>{
> int i, round, method;
> Block k, start;
> struct timeval start_t, stop_t;
> long usecs;
> Block *array = (Block *) calloc(NBuffers, sizeof(Block));
>
> start = (Block)0xff3386;
> for (i = 0; i < NBuffers; i++)
> array[i] = start + BLCKSZ*i;
>
> for (method = 0; method < 3; method ++)
> {
> start = (Block)0xff3386;
> for (round = 0; round < 3; round ++)
> {
> gettimeofday(&start_t, NULL);
> if (method == 0)
> {
> for (i = 0; i < NBuffers; i++)
> k = array[i];
> }
> if (method == 1)
> {
> for (i = 0; i < NBuffers; i++)
> k = start + i*BLCKSZ;
> }
> if (method == 2)
> {
> for (i = 0; i < NBuffers; i++)
> k = start + (i<<13);
> }
> gettimeofday(&stop_t, NULL);
>
> if (stop_t.tv_usec < start_t.tv_usec)
> {
> stop_t.tv_sec--;
> stop_t.tv_usec += 1000000;
> }
>
> usecs = (long) (stop_t.tv_sec - start_t.tv_sec) * 1000000
> + (long) (stop_t.tv_usec - start_t.tv_usec);
>
> fprintf (stdout, "duration round %d of %s method: %ld.%03ld ms\n",
> round + 1,
> method==0?"array":method==1?"mul":"shift",
> (long) ((stop_t.tv_sec - start_t.tv_sec) * 1000 +
> (stop_t.tv_usec - start_t.tv_usec) / 1000),
> (long) (stop_t.tv_usec - start_t.tv_usec) % 1000);
> }
> }
>}
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>
>

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2005-08-11 15:24:45 Re: PL/pgSQL: #option select_into_1_row (was SELECT INTO
Previous Message Matt Miller 2005-08-11 15:04:36 Re: PL/pgSQL: #option select_into_1_row (was SELECT INTO