Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » clear / rectfill performance

This thread is locked; no one can reply to it. rss feed Print
clear / rectfill performance
CGamesPlay
Member #2,559
July 2002
avatar

Okay, I've written a test to compare the performance of clear(screen) versus a rectfill over the entire screen. Logic dictates that clear(screen) should be faster or equal, but practice differs.

1#include <allegro.h>
2#include <stdio.h>
3#include <sys/time.h>
4 
5int clear_usec = 0;
6int rectfill_usec = 0;
7 
8void test()
9{
10 struct timeval start, end;
11 unsigned int usec;
12 int i;
13 
14 gettimeofday(&start, NULL);
15 for(i = 0; i < 1000; i++)
16 {
17 clear(screen);
18 }
19 gettimeofday(&end, NULL);
20
21 usec = end.tv_usec - start.tv_usec + 1000000 * (end.tv_sec - start.tv_sec);
22 clear_usec += usec;
23 
24 gettimeofday(&start, NULL);
25 for(i = 0; i < 1000; i++)
26 {
27 rectfill(screen, 0, 0, SCREEN_W - 1, SCREEN_H - 1, makecol(0, 0, 0));
28 }
29 gettimeofday(&end, NULL);
30
31 usec = end.tv_usec - start.tv_usec + 1000000 * (end.tv_sec - start.tv_sec);
32 rectfill_usec += usec;
33}
34 
35main()
36{
37 allegro_init();
38 set_color_depth(24);
39 set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
40
41 test();
42 test();
43 test();
44
45 printf("Qty.\tfunction\tmsec\tusec/call\n");
46 printf("3000\trectfill\t%d\t%d\n", rectfill_usec / 1000, rectfill_usec / 3000);
47 printf("3000\tclear(screen)\t%d\t%d\n", clear_usec / 1000, clear_usec / 3000);
48 printf("\n");
49 printf("gfx_driver->name = %s\n", gfx_driver->name);
50
51 return 0;
52}

Qty.    function        msec    usec/call
3000    rectfill        6729    2243
3000    clear(screen)   8975    2991

gfx_driver->name = X11 fullscreen

Why is this? What are others results?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

gnolam
Member #2,030
March 2002
avatar

So what are the results with a civilized color depth?

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

CGamesPlay
Member #2,559
July 2002
avatar

Even more pronounced. At 16 bpp:

Qty.    function        msec    usec/call
3000    rectfill        4099    1366
3000    clear(screen)   8857    2952

gfx_driver->name = X11 fullscreen

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

HoHo
Member #4,534
April 2004
avatar

But what about 32bit?

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

Matthew Leverton
Supreme Loser
January 1999
avatar

At 640x480, timing for roughly 1 second.

   Driver               cd    rect clear
------------------------------------------
   DirectDraw window  32-bit   940   941
   DirectDraw window  24-bit   688   688
   DirectDraw window  16-bit   789   791
   DirectDraw window  15-bit   781   789
   DirectDraw window   8-bit   959   957
    DirectDraw accel  32-bit  2905  2905
    DirectDraw accel  16-bit  5498  5517
    DirectDraw accel   8-bit 10575 10848

juvinious
Member #5,145
October 2004
avatar

Here I told cgames earlier I was going to give him a modified one with qpc for windows so here:

1 
2#include <allegro.h>
3#ifdef ALLEGRO_WINDOWS
4#include <winalleg.h>
5#include <windows.h>
6#else
7#include <stdio.h>
8#include <sys/time.h>
9#endif
10 
11#ifdef ALLEGRO_WINDOWS
12unsigned long long get_usec(unsigned long long startTime)
13{
14 static int onetime = 0;
15 static unsigned long long freq = 0, currentTime;
16 
17 if(!onetime) {
18 onetime = 1;
19 QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
20 }
21 
22 QueryPerformanceCounter((LARGE_INTEGER*)&currentTime);
23 
24 currentTime *= 1000000;
25 currentTime /= freq;
26 
27 return currentTime - startTime * 1000;
28}
29#endif
30 
31int clear_usec = 0;
32int rectfill_usec = 0;
33 
34void test()
35{
36#ifdef ALLEGRO_WINDOWS
37 unsigned long long start, end;
38
39 unsigned long long usec;
40 int i;
41
42 start = GetTickCount();
43 for(i = 0; i < 1000; i++)
44 {
45 clear(screen);
46 }
47 clear_usec +=get_usec(start);
48
49 start = GetTickCount();
50 for(i = 0; i < 1000; i++)
51 {
52 rectfill(screen, 0, 0, SCREEN_W - 1, SCREEN_H - 1, makecol(0, 0, 0));
53 }
54 rectfill_usec +=get_usec(start);
55
56#else
57 struct timeval start, end;
58 unsigned int usec;
59 int i;
60 
61 gettimeofday(&start, NULL);
62 for(i = 0; i < 1000; i++)
63 {
64 clear(screen);
65 }
66 gettimeofday(&end, NULL);
67
68 usec = end.tv_usec - start.tv_usec + 1000000 * (end.tv_sec - start.tv_sec);
69 clear_usec += usec;
70 
71 gettimeofday(&start, NULL);
72 for(i = 0; i < 1000; i++)
73 {
74 rectfill(screen, 0, 0, SCREEN_W - 1, SCREEN_H - 1, makecol(0, 0, 0));
75 }
76 gettimeofday(&end, NULL);
77
78 usec = end.tv_usec - start.tv_usec + 1000000 * (end.tv_sec - start.tv_sec);
79 rectfill_usec += usec;
80#endif
81
82 
83}
84 
85main()
86{
87 allegro_init();
88 set_color_depth(24);
89 set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
90
91 test();
92 test();
93 test();
94
95 printf("Qty.\tfunction\tmsec\tusec/call\n");
96 printf("3000\trectfill\t%d\t%d\n", rectfill_usec / 1000, rectfill_usec / 3000);
97 printf("3000\tclear(screen)\t%d\t%d\n", clear_usec / 1000, clear_usec / 3000);
98 printf("\n");
99 printf("gfx_driver->name = %s\n", gfx_driver->name);
100
101 return 0;
102}
103END_OF_MAIN()

On linux:

Qty.    function        msec    usec/call
3000    rectfill        9504   3168
3000    clear(screen)   9523   3174

gfx_driver->name = X11 fullscreen

Output from windows, but it could be off because of being in virtualbox:

Qty.    function        msec    usec/call
3000    rectfill        24546   8182
3000    clear(screen)   24614   8204

gfx_driver->name = DirectDraw accel

Now windows guys can get in on the action, hopefully that qpc stuff is correct if not, somebody can correct it ::)

__________________________________________
Paintown

Neil Walker
Member #210
April 2000
avatar

Why would anyone want to clear the screen directly and frequently? surely as a meaningful test you should be performing it on a offscreen/memory buffer.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

surely as a meaningful test

I'm testing it because the issue came up.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Elias
Member #358
May 2000

I did some timing here in linux (timing CPU time using clock) and results are (with C-only version of Allegro):

clearing a 640x480 32bit bitmap:
rectfill: 2427.2 / sec
clear: 2457.0 / sec
memset: 2525.3 / sec

clearing a 16x16 32bit bitmap:
rectfill: 1008064.5 / sec
clear: 1901140.7 / sec
memset: 4784689.0 / sec

So, my conclusion would be, rectfill and clear have about the same performance on memory bitmaps normally (the difference for 640x480 is like 1% so probably far below the error margin of my test), and they do very well as even memset doesn't really do better.

In the 16x16 test then, I did measure much more the various overheads than anything else, so memset wins clearly being twice as fast as clear (which has to do vtable access for each call and so on) being again twice as fast as rectfill (probably also has to do clipping checks additionally, maybe even calls hline for each line or something).

But the relevant test, clearing the 640x480 bitmap, it really doesn't matter at all which of the three to use.

--
"Either help out or stop whining" - Evert

Go to: