Hello,

With gcc-4 on Ubuntu AMD Athlon 2600 Barton:


[EMAIL PROTECTED]:~$ ./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
[EMAIL PROTECTED]:~$

Sincerely,

Joshua D. Drake


Qingqing Zhou wrote:

"Tom Lane" <[EMAIL PROTECTED]> 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


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org

Reply via email to