В продолжение
http://rsdn.ru/Forum/Message.aspx?mid=988750&only=1Автор: c-smile
Дата: 15.01.05
Теперь уже с D от DigitalMars
С# Java VC6 D (optimised+inlining) D (default)
230 457 705 735 341
Если честно я был приятно поражен. Вальтер Брайт — автор D (он делал Zortech C++/Symantec C++ и Symantec Java)
как всегда на высоте. Уважаю.
D компилириуемый и имеет GC. Минимальный размер exe под Win32 — 85kb. И больше ничего не надо.
Язык — элегантен.
Вот оно шастя, елы палы
Тест — практически один в один вариант С#:
// to compile with optimisations use:
// dmd.exe alphablend -inline -O -release
module tests.AlphaBlend;
import std.stdio;
import std.perf;
const int width = 1000;
const int height = 1000;
class AlphaBlend
{
public struct Color
{
byte r,g,b,a;
};
int randomSeed = 1234;
public Color[height][width] frameBuffer;
public int random()
{
return ((randomSeed = randomSeed * 214013 + 2531011) >> 16) & 0x7FFFFFFF;
}
// Variant 1
public void AlphaBlendSpan(int x, int y, int len, Color c)
{
int i;
for(i = 0; i < len; i++)
{
Color* cd = &frameBuffer[y][x+i];
cd.r = cast(byte)((((c.r - cd.r) * c.a) + (cd.r << 8)) >> 8);
cd.g = cast(byte)((((c.g - cd.g) * c.a) + (cd.g << 8)) >> 8);
cd.b = cast(byte)((((c.b - cd.b) * c.a) + (cd.b << 8)) >> 8);
cd.a = cast(byte)((c.a + cd.a) - ((c.a * cd.a) >> 8));
}
}
public void AlphaBlendRect(int x, int y, int w, int h)
{
Color c;
c.r = cast(byte)(random() % 255);
c.g = cast(byte)(random() % 255);
c.b = cast(byte)(random() % 255);
c.a = cast(byte)(random() % 255);
for(int i = 0; i < h; i++)
{
AlphaBlendSpan(x, y+i, w, c);
}
}
public void TestAlphaBlend(int n)
{
for(int i = 0; i < n; i++)
{
int x1 = random() % width;
int y1 = random() % height;
int x2 = random() % width;
int y2 = random() % height;
int t;
if (x1 > x2) { t = x1; x1 = x2; x2 = t; }
if (y1 > y2) { t = y1; y1 = y2; y2 = t; }
AlphaBlendRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
}
}
};
int main(char[][] args)
{
ProcessTimesCounter counter = new ProcessTimesCounter();
int n = 1000;
AlphaBlend ab = new AlphaBlend();
counter.start();
ab.TestAlphaBlend(n);
counter.stop();
ProcessTimesCounter.interval_type ms1 = counter.milliseconds();
writef("Performance = %g rectangles per second\n", (cast(double)(n) / cast(double)ms1) * 1000.0 );
return 0;
}