Windows XP sp3, Pentium DualCore 1.6 GHz
GNAT2012 9.4 fps
TinyC 0.9.24 2.3 fps
VC2010 12.3 fps
Ada GNAT 2012
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
procedure BlurGnat is
package Duration_IO is new Ada.Text_IO.Fixed_IO(Duration);
use Duration_IO;
width : constant integer := 640;
height : constant integer := 480;
blurRange : constant integer := 13;
frames : constant integer := 1000;
type Byte is range 0 .. 255; for Byte'Size use 8;
type Frame is array (0 .. (width*height*3-1)) of Byte;
procedure Blur(inar : in Frame; outar : out Frame) is
RED : constant integer := 0;
GREEN : constant integer := 1;
BLUE : constant integer := 2;
function index(x: integer; y: integer; color: integer) return integer is
begin
return width*y*3+x*3+color;
end index;
begin
for y in 1..height-1-1 loop
for x in 1..width-1-1 loop
outar(index(x,y,RED)) := Byte(
(Integer(inar(index(x,y-1,RED))) + Integer(inar(index(x,y+1,RED))) +
Integer(inar(index(x-1,y,RED))) + Integer(inar(index(x+1,y,RED)))) / 4);
outar(index(x,y,GREEN)) := Byte(
(Integer(inar(index(x,y-1,GREEN))) + Integer(inar(index(x,y+1,GREEN))) +
Integer(inar(index(x-1,y,GREEN))) + Integer(inar(index(x+1,y,GREEN)))) / 4);
outar(index(x,y,BLUE)) := Byte(
(Integer(inar(index(x,y-1,BLUE))) + Integer(inar(index(x,y+1,BLUE))) +
Integer(inar(index(x-1,y,BLUE))) + Integer(inar(index(x+1,y,BLUE)))) / 4);
end loop;
end loop;
end Blur;
inarr : Frame;
outarr : Frame;
time_begin : Time;
time_elapsed : Duration;
begin
for i in Frame'Range loop inarr(i) := 127; end loop;
time_begin := Clock;
for nn in 1..frames loop
for i in 1..blurRange loop
Blur(inarr, outarr);
Blur(outarr, inarr);
end loop;
end loop;
time_elapsed := To_Duration(Clock - time_begin);
Put("BlurGNAT: fps = "); Put(Float(frames)/Float(time_elapsed));
Put(" time = "); Put(time_elapsed);
Put_Line(" sec");
end BlurGnat;
TinyC 0.9.24
#include <stdio.h>
#include <time.h>
#define width 640
#define height 480
#define blurRange 13
#define frames 200
void Blur(char* inar, char* outar)
{
#define RED 0
#define GREEN 1
#define BLUE 2
#define index(x,y,color) ((width)*(y)*3+(x)*3+(color))
int x, y;
for (y=1; y<height-1; y++)
for (x=1; x<width-1; x++) {
outar[index(x,y,RED)]=
((int)inar[index(x,y-1,RED)]+
(int)inar[index(x,y+1,RED)]+
(int)inar[index(x-1,y,RED)]+
(int)inar[index(x+1,y,RED)]) >> 2;
outar[index(x,y,GREEN)]=
((int)inar[index(x,y-1,GREEN)]+
(int)inar[index(x,y+1,GREEN)]+
(int)inar[index(x-1,y,GREEN)]+
(int)inar[index(x+1,y,GREEN)]) >> 2;
outar[index(x,y,BLUE)]=
((int)inar[index(x,y-1,BLUE)]+
(int)inar[index(x,y+1,BLUE)]+
(int)inar[index(x-1,y,BLUE)]+
(int)inar[index(x+1,y,BLUE)]) >> 2;
}
}
char in [width*height*3];
char out[width*height*3];
int main(void)
{
int nn, i;
time_t begin, end;
double seconds;
time(&begin);
for (nn=0; nn<frames; nn++)
{
for (i=0; i<blurRange; i++)
{
Blur(in, out);
Blur(out, in);
}
}
time(&end);
seconds = difftime(end, begin);
printf("%f %d", (float)((double)frames)/seconds, (int)(seconds+0.5));
return 0;
}