I am using devcpp since a few days ago.
I have 2 functions for drawing anti-aliased sprites to a memory buffer, one is allegro's draw_trans_sprite(), and the other one is Fladimir's AlphaBlend32().
I want to know how much faster the fastest one is.
I am linking to liballp.a, and the compiler option -pg.
Attached is the source file with an alpha sprite for testing.
Here is the loop, I am calling both functions at the same time, I think that's the best way for testing, any advices?
1 | int main() { |
2 | /* Setup Allegro */ |
3 | allegro_init(); |
4 | install_keyboard(); |
5 | install_mouse(); |
6 | |
7 | /*set color depth in 32bpp */ |
8 | set_color_depth( 32 ); |
9 | set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0 ); |
10 | //set_gfx_mode( GFX_AUTODETECT, 800, 600, 0, 0 ); |
11 | |
12 | BITMAP *buffer = create_bitmap( SCREEN_W, SCREEN_H ); |
13 | clear_to_color(buffer, makecol(255, 0, 0)); |
14 | |
15 | /* must be a 32-bit bitmap with an alpha channel! */ |
16 | BITMAP *sprite = load_bitmap( "olafito.tga", NULL ); |
17 | if(sprite == NULL ) allegro_message("not found\n"); |
18 | |
19 | set_alpha_blender(); |
20 | |
21 | do { |
22 | |
23 | |
24 | /* draw with AlphaBlend32*/ |
25 | AlphaBlend32( sprite, buffer, mouse_x-sprite->w/2, mouse_y-sprite->h/2, 255 ); |
26 | |
27 | /* draw with draw_trans_sprite */ |
28 | draw_trans_sprite(buffer, sprite, mouse_x-sprite->w/2, mouse_y-sprite->h/2); |
29 | |
30 | |
31 | blit( buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H ); |
32 | |
33 | |
34 | }while (!key[KEY_ESC]); |
35 | return 0; |
36 | } |
.
.
Linking with profiling versions of Allegro is only meaningful if you want to profile Allegro itself. If you want to profile your program then compile it with -pg and link with regular allegro. That way allegro won't be slowed down by being profiled.
In case of your program I'd just have two loops that repeat one or the other function for million times. The one who takes less time wins. Profilers won't be much of use to you, unless you intend to improve implementations of these functions.
Linking with profiling versions of Allegro is only meaningful if you want to profile Allegro itself. If you want to profile your program then compile it with -pg and link with regular allegro. That way allegro won't be slowed down by being profiled.
I did not know that, in MSVC6 I was using the debug and profile version of allegro for debuging and profiling my program, that was not really necesary?
Back on topic, I changed my loop code following your advice.
I tested the program with draw_trans_sprite and AlphaBlend32, one first, and the other later.
.
.
This is what I obtained for AlphaBlend32:
.
.
.
.
This is what I obtained for draw_trans_sprite
.
.
.
.
What does that mean? I can't even read it!>:(
As I said before, profiling is not the best way to find out what is faster, at least not in your case. Problem is, profiling code adds a lot of overhead and it won't give you all that accurate results. Also comparing two programs and their profiler outputs is not very meaningful, especially as Allegro used release code and Fladimir's alphablend functions used much slower profiling code (assuming you added his functions to your project).
As I said, just call each function lots of times (program runtime should be >10 seconds) and time how long it takes for the loops to complete. You can use Allegro timers for measuring the time passed.
Basically, your program should look like this:
1 | initialize program |
2 | |
3 | initialize allegro blenders |
4 | al_begin=time() |
5 | loop while counter>0{ |
6 | blend something |
7 | counter-- |
8 | } |
9 | al_end=time() |
10 | |
11 | initialize Fladimir's blenders |
12 | fl_begin=time() |
13 | loop while counter>0{ |
14 | blend something |
15 | counter-- |
16 | } |
17 | fl_end=time() |
18 | print "allegro took " al_end-al_begin |
19 | print "Fladimir tool" fl_end-fl_begin |
It is not that profiling in general is meaningless. Just that it isn't the best tool in your case.
For timing of this sort I'd use something a little higher res like gettimeofday on unix.
High-res is meaningful if you try to time stuff that take less than a few tenths of a second. For stuff that takes >5s any other method is good enough