File: testrgb.pl

package info (click to toggle)
libgtk-perl 0.7009-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,956 kB
  • ctags: 2,260
  • sloc: perl: 13,998; xml: 9,919; ansic: 2,894; makefile: 64; cpp: 45
file content (130 lines) | stat: -rw-r--r-- 3,892 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl -w

use Gtk -init;
use Time::HiRes qw (time);

use constant WIDTH => 640;
use constant HEIGHT => 480;
use constant FALSE => 0;
use constant TRUE => 1;
use constant NUM_ITERS => 100;

#use Benchmark 'cmpthese';

#cmpthese(2, {
#	'append' => 'use integer;$buf="";$val = 0; for ($j = 0; $j < WIDTH * HEIGHT * 6; $j++) {$buf .=chr(($val + (($val + int(rand (256))) >> 1)) >> 1)}',
#  	#'pack' => '$buf="";$val = 0;$buf .= pack("C*", map {($val + (($val + int(rand (256))) >> 1)) >> 1} 0..WIDTH*6) foreach (0..HEIGHT);',
#  	'pack2' => 'use integer;$buf="";$val = 0;$buf .= pack("C*", map {($val + (($val + int(rand (256))) >> 1)) >> 1} 0..WIDTH) foreach (0..HEIGHT*6);',
#});

sub testrgb_rgb_test {
  my $drawing_area = shift;
  my $buf = '';
  my ($j, $i, $val, $offset, $dither, $start_time, $total_time, $x, $y, $dith_max);

  $val = 0;
  #for ($j = 0; $j < WIDTH * HEIGHT * 6; $j++)
  #  {
  #    $val = ($val + (($val + int(rand (256))) >> 1)) >> 1;
  #    $buf .= chr($val);
  #  }
  {
  	use integer;
	$buf .= pack("c*", map {($val + (($val + int(rand (256))) >> 1)) >> 1} 0..WIDTH) foreach (0..HEIGHT*6);
  }

  # Let's warm up the cache, and also wait for the window manager
  #  to settle. 
  print "warm up the cache\n";
  for ($i = 0; 0 && $i < NUM_ITERS/10; $i++)
    {
      $offset = int(rand (WIDTH * HEIGHT * 3)) & -4;
      $drawing_area->window->draw_rgb_image (
			  $drawing_area->style->white_gc,
			  0, 0, WIDTH, HEIGHT,
			  'none',
			  substr($buf, $offset), WIDTH * 3);
			  #$buf, WIDTH * 3);
    }

  $dith_max = Gtk::Gdk::Rgb->ditherable ? 2 : 1;

  print "start\n";
  for ($dither = 0; $dither < $dith_max; $dither++)
    {
      $start_time = time ();
      for ($i = 0; $i < NUM_ITERS; $i++)
	{
	  $offset = int(rand (WIDTH * HEIGHT * 3)) & -4;
	  $drawing_area->window->draw_rgb_image (
			      $drawing_area->style->white_gc,
			      0, 0, WIDTH, HEIGHT,
			      $dither ? 'max' : 'none',
				  #Gtk::constsubstr($buf, $offset), WIDTH * 3);
			      substr($buf, $offset), WIDTH * 3);
			      #$buf, WIDTH * 3);
	}
      $total_time = time () - $start_time;
      printf "Color test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
	       $dither ? " (dithered)" : "",
	       $total_time,
	       NUM_ITERS / $total_time,
	       NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / $total_time;
    }

  for ($dither = 0; $dither < $dith_max; $dither++)
    {
      $start_time = time ();
      for ($i = 0; $i < NUM_ITERS; $i++)
	{
	  $offset = int(rand (WIDTH * HEIGHT)) & -4;
	  $drawing_area->window->draw_gray_image(
			       $drawing_area->style->white_gc,
			       0, 0, WIDTH, HEIGHT,
			       $dither ? 'max' : 'none',
				   #Gtk::constsubstr($buf, $offset), WIDTH);
			       substr($buf, $offset), WIDTH);
			       #$buf, WIDTH);
	}
      $total_time = time () - $start_time;
      printf "Grayscale test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
	       $dither ? " (dithered)" : "",
	       $total_time,
	       NUM_ITERS / $total_time,
	       NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / $total_time;
    }

  print ("Please submit these results to http://www.levien.com/gdkrgb/survey.html\n");

}

  Gtk::Gdk::Rgb->init;
  $window = Gtk::Widget->new ('Gtk::Window',
			   "GtkWindow::type", 'toplevel',
			   "GtkWindow::title", "testrgb",
			   "GtkWindow::allow_shrink", FALSE);
  $window->signal_connect( "destroy", sub {Gtk->main_quit});

  $vbox = new Gtk::VBox (FALSE, 0);

  $drawing_area = new Gtk::DrawingArea;

  $drawing_area->set_usize (WIDTH, HEIGHT);
  $vbox->pack_start ($drawing_area, FALSE, FALSE, 0);
  $drawing_area->show;

  $button = new Gtk::Button ("Quit");
  $vbox->pack_start ($button, FALSE, FALSE, 0);
  $button->signal_connect ("clicked", sub {$window->destroy});

  $button->show;

  $window->add ($vbox);
  $vbox->show;

  $window->show;

  testrgb_rgb_test ($drawing_area);

Gtk->main;