libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] SubImages no longer need to be distinct from BasicImage


From: E. Rosten
Subject: [libcvd-members] SubImages no longer need to be distinct from BasicImages.
Date: Wed, 29 Oct 2008 15:13:29 +0000 (GMT)

SubImages were originally distinct from BasicImages for speed, since BasicImages used raw pointers for iterators, and SubImage iterators were somewhat more complex.

Here are the timing results for a simple function (summing up all pixels in an image):


forloop 16.3304  (494985830000)
imageref 20.2895  (494985830000)
basicimage_iterator 16.7697  (494985830000)
subimage_iterator 16.4321  (494985830000)
subimage_iterator_fastend 17.8282  (494985830000)
subimage_iterator_stl 16.2188  (494985830000)
basicimage_iterator_stl 16.4601  (494985830000)

Interesting points:

ImageRef scanning is no longer 10x slower than other methods

pointers are slower than more complex iterators.

The fastend speed hack is now a slowness hack.

The STL is faster than the hand coded algorithm.

gcc version 4.3.1 20080507 (prerelease)

CPU is:

cpu family      : 15
model           : 3
model name      : Intel(R) Pentium(R) 4 CPU 3.20GHz
stepping        : 4
cpu MHz         : 3207.370
cache size      : 1024 KB


Anyone else want to check these results?


Here's the code:

#include <cvd/image.h>
#include <cvd/timer.h>
#include <iostream>
#include <functional>
#include <numeric>
#include <cstdlib>
using namespace CVD;
using namespace std;

int basicimage_iterator_stl(const BasicImage<int>& im)
{
        return accumulate(im.begin(), im.end(), 0, plus<int>());
}

int subimage_iterator_stl(const SubImage<int>& im)
{
        return accumulate(im.begin(), im.end(), 0, plus<int>());
}

int basicimage_iterator(const BasicImage<int>& im)
{
        int sum=0;
        for(BasicImage<int>::const_iterator i = im.begin(); i != im.end(); i++)
                sum += *i;

        return sum;
}

int subimage_iterator_fastend(const SubImage<int>& im)
{
        int sum=0;
        for(SubImage<int>::const_iterator i = im.begin(); i != im.fastend(); 
i++)
                sum += *i;

        return sum;
}

int subimage_iterator(const SubImage<int>& im)
{
        int sum=0;
        for(SubImage<int>::const_iterator i = im.begin(); i != im.end(); i++)
                sum += *i;

        return sum;
}


int forloop(const SubImage<int>& im)
{
        int sum=0;
        for(int y=0; y < im.size().y; y++)
                for(int x=0; x < im.size().x; x++)
                        sum += im[y][x];

        return sum;
}


int imageref(const SubImage<int>& im)
{
        int sum=0;
        ImageRef scan(0,0);

        do
        {
                sum += im[scan];
        }while(scan.next(im.size()));

        return sum;
}

#define TEST(X)\
{\
  long long sum=0;\
  cvd_timer t;\
  for(int i=0; i < 10000; i++)\
        sum += X(im);\
  cout << #X << " " << t.get_time() << "  (" << sum << ")\n";\
}


int main()
{
        Image<int> im(ImageRef(1000,1000));

        for(Image<int>::iterator i=im.begin(); i != im.end(); i++)
                *i = rand() % 100;

        TEST(forloop);
        TEST(imageref);
        TEST(basicimage_iterator);
        TEST(subimage_iterator);
        TEST(subimage_iterator_fastend);
        TEST(subimage_iterator_stl);
        TEST(basicimage_iterator_stl);
}



--
(You can't go wrong with psycho-rats.)       (er258)(@)(eng.cam)(.ac.uk)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{10}d/r{roll}d f 5/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
for /s 15 d f pop 240 420 m 0 1 3 { 4 2 1 r sub -1 r show } for showpage




reply via email to

[Prev in Thread] Current Thread [Next in Thread]