Re: Some benchmarking on graphics

From: Vadim Belman <voland_at_lflat.org>
Date: Sat, 22 Feb 2003 16:32:13 +0200
To: prima_at_prima.eu.org

Dmitry Karasik wrote:
> Here:
> FreeBSD v4.3, XFree86 v4.0.3, AMD Athlon 650MHz, 800x800
>
> Canvas Image DeviceBitmap
> 0 19 2 11
> B 11 2 9
> M 2 1 2
> S 21 3 12
> BM 2 1 2
> BS 13 3 11
> MS 3 2 2
> BMS 2 1 2

        Hm, looks much slower than on my system. FreeBSD 4.7, XFree86 4.2.1,
Athlon 1600Mhz, 1152x864x24bpp, NVidia GeForce3. It shall be sufficient
to describe the environment, hopefully.

> On X though your benchmarking would be inaccurate, since you
> are using Widget::repaint call - which can be cached, and
> involves a client-server roundtrip. Explicit begin_paint/end_paint
> should do better.

        Anyway, here is the results following. In fact, I have changed the
script a little bit by fixing a warning because $myVersion is used
before initialized. Also, 'Save' button has been added which stores all
results in PrimaBenchmark.rep file. So, nothing to affect the benchmark
itself, as one can see.

        Here is what I've got:

Canvas (NB) (MC) 81 fps @ 864 x 588
Image (NB) (MC) 10 fps @ 864 x 588
DeviceBitmap (NB) (MC) 84 fps @ 864 x 588
Canvas (B) (MC) 75 fps @ 864 x 588
Image (B) (MC) 12 fps @ 864 x 588
DeviceBitmap (B) (MC) 74 fps @ 864 x 588
Canvas (NB) (SC) 88 fps @ 864 x 588
Image (NB) (SC) 11 fps @ 864 x 588
DeviceBitmap (NB) (SC) 111 fps @ 864 x 588
Canvas (B) (SC) 109 fps @ 864 x 588
Image (B) (SC) 11 fps @ 864 x 588
DeviceBitmap (B) (SC) 92 fps @ 864 x 588

        The output has been modified to fit the message width. Here NB/B stands
for nonbuffered/buffered, MC/SC - multi-/singlecolor, respectively.

        It looks pleasantly as for my eyes. 8)

-- 
			/Vadim Belman

#!/usr/bin/perl -w

BEGIN {
    use vars qw($myVersion);
    $myVersion='BenchCanvas 0.30';
}

=head1 BenchCanvas
=item SUMMARY
Benchmark for some unexpected graphics performance issues in Prima 1.08
Tests:
   direct draw on canvas (buffered and non-buffered)
   draw using internal Image
   draw usind internal Bitmap
=item RESULTS
Prima 1.08 Windows 2000 Laptop about 800 MHz
Size 800x800, 1000 lines
direct: 18 fps (buffered: 22 fps)
image: 3 to 8 fps (unexplained behaviour: shifts from 3 to 8 after some time)
bitmap: 23 fps

Impressiv speed up also when removing canvas.color calls....
=item AUTHOR
(c) 2003 by Michael Peuser post_at_mpeuser.de
=cut

use vars qw(
    @results
);

use Time::HiRes qw (time ); #for micro seconds!

use Prima;
use Prima::Label;
use Prima::Buttons;
use Prima::Application (name => $myVersion);
use Prima::MsgBox;

my $nLines=1000;

sub nosub { };

   
$mainW = Prima::Window-> create(
   name=>$myVersion,
   onDestroy => sub {
       $::application-> close() },
);

$mainW->font(size=>10);

# Layout params for buttons
my $bX=10;
my $bXGrid=100;
my $bYGrid=30;

# display space
my $labelW = $mainW->insert(
    Label =>
    text=>$myVersion,
    backColor=>cl::White,
    rect => [$bX, 0,$mainW->width(), $bYGrid],
);

# canvas box
my $cW;
$cW = $mainW->insert(
    Widget =>
    buffered => 0,
    growMode => gm::Client,
    rect => [0, 2*$bYGrid, $mainW->width(),$mainW->height()],

    onSize=> sub {
        return unless $cW;
        $cW->begin_paint();
        $cW->clear();
            $cW->end_paint();
        }
);

# start direct draw on canvas
$mainW->insert(
    Button =>
    name => "Canvas",
    origin => [$bX, $bYGrid],
    onClick=> sub {
        my $self=shift;
        $cW->set(onPaint => sub {
            my $c=shift;
            $c-> color(rand 0xffffff);
            for (1..$nLines) {
                $c-> color(rand 0xffffff) unless $singleColor;
                $c->line(rand $cW->width(),rand $cW->height(),rand $cW->width(),rand $cW->height());
                }
                     });
            
            my $t1=time()+1; # give me one second
            my $N=0;
            while(time()<=$t1) {
            $N++;
            
            $cW->repaint();
            $::application->yield()
        } # endWHILE
        $self->{N}=$N;
        display($self);
    } # end onClick
);

# start draw on image
$bX += $bXGrid;
$mainW->insert(
    Button =>
    name => "Image",
    origin => [$bX, $bYGrid],
    onClick=> sub {
        my $self=shift;
        $img->destroy() if $img;
        $img = Prima::Image->create(height=>$cW->height(), width=>$cW->width());
        $cW->set(onPaint => sub { $_[1]->put_image(
                                    ($cW->width()-$img->width())/2,
                                    ($cW->height()-$img->height())/2,
                                    $img)});
        my $t1=time()+1; # give me one second
        my $N=0;
        while(time()<=$t1) {
        $N++;
        $img->begin_paint();
        $img->clear();
        $img-> color(rand 0xffffff);

        for (1..$nLines) {
            $img-> color(rand 0xffffff) unless $singleColor;
            $img->line(rand $cW->width(),rand $cW->height(),rand $cW->width(),rand $cW->height());
            }
        $img->end_paint();
        $cW->repaint();
        $::application->yield()
        } # endWHILE
        $self->{N}=$N;
        display($self);
    }, # end onClick
);

# start draw on bitmap
$bX += $bXGrid;
$mainW->insert(
    Button =>
    name => "DeviceBitmap",
    origin => [$bX, $bYGrid],
    onClick=> sub {
        my $self=shift;
        $img->destroy() if $img;
        $img = Prima::DeviceBitmap->create(height=>$cW->height(), width=>$cW->width());
        $cW->set(onPaint => sub { $_[1]->put_image(
                                    ($cW->width()-$img->width())/2,
                                    ($cW->height()-$img->height())/2,
                                    $img)});
 
        my $t1=time()+1; # give me one second
        my $N=0;
        while(time()<=$t1) {
        $N++;
        $img->begin_paint();
        $img->clear();
        $img-> color(rand 0xffffff);
        for (1..$nLines) {
            $img-> color(rand 0xffffff) unless $singleColor;
            $img->line(rand $cW->width(),rand $cW->height(),rand $cW->width(),rand $cW->height());
            }
        $img->end_paint();
        $cW->repaint();
        $::application->yield()
        } # endWHILE
        $self->{N}=$N;
        display($self);
    }, # end onClick

);

# save results
$bX += $bXGrid;
$mainW->insert(
    Button =>
    name => "SaveResults",
    text => "Save",
    origin => [$bX, $bYGrid],
    onClick => sub {
        if (open REP, ">PrimaBenchmark.rep") {
            print REP map { "$_\n" } @results;
            close REP;
        } else {
            Prima::MsgBox::message(
                "Failed to write to PrimaBenchmark.rep: $!",
                mb::Error
            );
        }
    }
);

# some options
# -------------
# toggle mainW.bufferered

$bX += $bXGrid;
$mainW->insert(
    CheckBox =>
    name => "buffered",
    origin => [$bX, $bYGrid],
    onCheck=> sub { $cW->buffered($_[1])}
);

$bX += $bXGrid;
# toggle nLines 1000/10_000
$mainW->insert(
    CheckBox =>
    name => "more lines",
    origin => [$bX, $bYGrid],
    onCheck=> sub { $nLines=1000+9000*$_[1]}
);

$bX += $bXGrid;
# toggle nLines 1000/10_000
$mainW->insert(
    CheckBox =>
    name => "single color",
    origin => [$bX, $bYGrid],
    onCheck=> sub { $singleColor=$_[1]}
);

sub display{
    my $b=shift;
    my ($kind, $N,$text) = ($b->name(), $b->{N});
    my ($x,$y,$bu,$colors) = (
        $cW->width,
        $cW->height,
        $cW->buffered ? "(buffered)":"(nonbuffered)",
        $singleColor ? "(single color)" : "(multicolor)",
    );
 
    my $repText = "$kind $bu $colors $N fps \@ $x x $y - $nLines lines";
    $labelW->text($repText);
    push @results, $repText;
}

sub newBitmap{
    
    my ($wwidth,$wheight)=@_;
    $img->destroy() if $img && $wwidth && $wheight;
    $img = Prima::DeviceBitmap->create(height=>$wheight,width=>$wwidth) if $wwidth && $wheight;

}

run Prima;

__END__
Received on Sat 22 Feb 2003 - 16:04:37 CET

This archive was generated by hypermail 2.2.0 : Sat 19 Mar 2011 - 18:35:04 CET