Here I have asked what is the difference between SDL_FillRect
and SDL_RenderFillRect
Here is code of my benchmark:
my $window = SDL2::Video::SDL_CreateWindow( 'Hello', 100, 100, 800, 600, 0x00000004 );
my $surface = SDL2::Video::SDL_GetWindowSurface( $window );
my $render = SDL2::Render::SDL_GetRenderer( $window );
SDL2::Render::SDL_SetRenderDrawColor( $render, 0, 0, 255, 255 );
use Benchmark ':all';
my $rect1 = SDL2::Rect->new({ x => 10, y => 10, h => 50, w => 50 });
timethese( 1000000, {
'Soft' => sub {
SDL2::Surface::SDL_FillRect( $surface, $rect1, 0x00FF0000 );
},
'Hard' => sub {
SDL2::Render::SDL_RenderFillRect( $render, $rect1 );
},
});
The result:
Benchmark: timing 1000000 iterations of Hard, Soft...
Hard: 20 wallclock secs (13.06 usr + 8.03 sys = 21.09 CPU) @ 47415.84/s (n=1000000)
Soft: 3 wallclock secs ( 2.91 usr + 0.01 sys = 2.92 CPU) @ 342465.75/s (n=1000000)
Why CPU-side
version of function is much faster?
Probably I something wrong while benchmarking?
UPD
When rectangle is more bigger:
my $rect1 = SDL2::Rect->new({ x => 10, y => 10, h => 550, w => 750 });
Benchmark: timing 100000 iterations of Hard, Soft...
Hard: 25 wallclock secs ( 1.51 usr + 2.50 sys = 4.01 CPU) @ 24937.66/s (n=100000)
Soft: 25 wallclock secs (24.80 usr + 0.00 sys = 24.80 CPU) @ 4032.26/s (n=100000)
Benchmark: timing 1000000 iterations of Hard, Soft...
Hard: 264 wallclock secs (16.67 usr + 23.98 sys = 40.65 CPU) @ 24600.25/s (n=1000000)
Soft: 259 wallclock secs (258.00 usr + 0.34 sys = 258.34 CPU) @ 3870.87/s (n=1000000)
User contributions licensed under CC BY-SA 3.0