Da ich seit einigen Wochen FreeBasic (FB) lerne, wollte ich AutoIt mit FreeBasic in Bezug auf GDI / GDI+ Geschwindigkeit testen.
Ich weiß, dass dies ein Vergleich David gegen Goliath ist, aber man sieht den krassen Unterschied.
Runde1 -> GDI Particles Mouse Attraction:
FB: 25.000 Partikel @ 1024x768
Au3: 1.000 Partikel @ 800x600.
AU3:
;coded by UEZ build 2016-07-28
;idea taken from http://jsdo.it/FumioNonaka/jQcv
#pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico")
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /pe /rm
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3"
#include <GUIConstantsEx.au3>
#include <WinAPIGdi.au3>
#include <WindowsConstants.au3>
AutoItSetOption("MouseCoordMode", 2)
AutoItSetOption("MustDeclareVars", 1)
Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit
Global Const $iW = 800, $iH = 600, $iParticles = 1000, $sTitle = "GDI Particles Mouse Attraction / Particles: " & $iParticles & " / FPS: "
Global $i, $iMouseX = $iW / 2, $iMouseY = $iH / 2
Global $tParticles = DllStructCreate( _
"float x[" & $iParticles & "];" & _
"float y[" & $iParticles & "];" & _
"float vx[" & $iParticles & "];" & _
"float vy[" & $iParticles & "];" & _
"float friction[" & $iParticles & "];" & _
"uint color[" & $iParticles & "]")
For $i = 1 To $iParticles
With $tParticles
.x(($i)) = Random() * $iW
.y(($i)) = Random() * $iH
.friction(($i)) = 0.975
;~ .color(($i)) = 0xFF000000 + Int(Random() * 0xFFFFFF)
.color(($i)) = 0xFFFFFFFF
EndWith
Next
AutoItSetOption("GUIOnEventMode", 1)
GDI_BurstingParticlesAnimation()
AutoItSetOption("GUIOnEventMode", 0)
Func GDI_BurstingParticlesAnimation()
$hGUI = GUICreate($sTitle & "0", $iW, $iH)
Local Const $hDC = _WinAPI_GetDC($hGUI)
Local $pBits, $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $tagBITMAPV5HEADER = ' & $tagBITMAPV5HEADER & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
With $tBIV5HDR
.bV5Size = DllStructGetSize($tBIV5HDR)
.bV5Width = $iW
.bV5Height = -$iH
.bV5Planes = 1
.bV5BitCount = 32
.bV5Compression = $BI_RGB
.bV5RedMask = 0x00FF0000
.bV5GreenMask = 0x0000FF00
.bV5BlueMask = 0x000000FF
.bV5AlphaMask = 0xFF000000
EndWith
Local Const $hBitmapGDI = _WinAPI_CreateDIBSection($hDC, $tBIV5HDR, $DIB_RGB_COLORS, $pBits)
Global $tBitmap = DllStructCreate("uint px[" & $iW * $iH & "]", $pBits)
Local Const $hGfxDC = _WinAPI_CreateCompatibleDC($hDC)
Local Const $hObjOld = _WinAPI_SelectObject($hGfxDC, $hBitmapGDI)
GUISetState(@SW_SHOW, $hGUI)
$bExit = False
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
AdlibRegister("CalcFPS", 1000)
Local $iX, $iY
Do
_WinAPI_BitBlt($hGfxDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $BLACKNESS)
For $i = 1 To $iParticles
MoveParticles(MouseGetPos(0), MouseGetPos(1), $i)
$iX = Int($tParticles.x(($i)))
$iY = Int($tParticles.y(($i))) * $iW
$tBitmap.px(($iY + $iX)) = $tParticles.color(($i)) ;write directly to the bitmap (one pixel)
Next
_WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $SRCCOPY)
$iFPS += 1
If $bExit Then ExitLoop
Until Not Sleep(10)
_WinAPI_SelectObject($hGfxDC, $hObjOld)
_WinAPI_ReleaseDC($hGUI, $hDC)
_WinAPI_DeleteDC($hGfxDC)
_WinAPI_DeleteObject($hBitmapGDI)
GUIDelete($hGUI)
EndFunc ;==>GDI_BurstingParticlesAnimation
Func _Exit()
$bExit = True
EndFunc ;==>_Exit
Func CalcFPS() ;display FPS
$iShowFPS = $iFPS
$iFPS = 0
WinSetTitle($hGUI, "", $sTitle & $iShowFPS)
EndFunc ;==>CalcFPS
Func MoveParticles($fX, $fY, $iPos, $fSpeed = 100)
Local $_x, $_y, $_vx, $_vy, $fDiffX, $fDiffY, $fSquare, $fRatio, $fAccX, $fAccY
$_x = $tParticles.x(($iPos))
$_y = $tParticles.y(($iPos))
$_vx = $tParticles.vx(($iPos))
$_vy = $tParticles.vy(($iPos))
$fDiffX = $fX - $_x
$fDiffY = $fY - $_y
$fSquare = ($fDiffX * $fDiffX + $fDiffY * $fDiffY)
$fRatio = $fSquare > 0 ? $fSpeed / $fSquare : 0
$fAccX = $fDiffX * $fRatio
$fAccY = $fDiffY * $fRatio
$_vx += $fAccX
$_vy += $fAccY
$_vx *= $tParticles.friction(($iPos))
$_vy *= $tParticles.friction(($iPos))
$_x += $_vx
$_y += $_vy
If $_x < 0 Then $_x += $iW
If $_x > $iW Then $_x -= $iW
If $_y < 0 Then $_y += $iH
If $_y > $iH Then $_y -= $iH
$tParticles.x(($iPos)) = $_x
$tParticles.y(($iPos)) = $_y
$tParticles.vx(($iPos)) = $_vx
$tParticles.vy(($iPos)) = $_vy
EndFunc ;==>MoveParticles
Alles anzeigen
FB:
'coded by UEZ build 2016-07-28
'idea taken from http://jsdo.it/FumioNonaka/jQcv
#include "windows.bi"
#include "fbgfx.bi"
Using FB
Type tParticles
x As Single
y As Single
vx As Single
vy As Single
friction As Single
argb As UInteger
End Type
Dim Shared As ULong iW = 1024, iH = 768, iParticles = 25000
Dim Shared aParticles(0 To iParticles - 1) As tParticles
Sub MoveParticles(fX As Single, fY As Single, iPos As ULong, fSpeed As Single)
Dim As Single _x, _y, _vx, _vy, fDiffX, fDiffY, fSquare, fRatio, fAccX, fAccY
_x = aParticles(iPos).x
_y = aParticles(iPos).y
_vx = aParticles(iPos).vx
_vy = aParticles(iPos).vy
fDiffX = fX - _x
fDiffY = fY - _y
fSquare = (fDiffX * fDiffX + fDiffY * fDiffY)
fRatio = IIf(fSquare > 0, fSpeed / fSquare, 0)
fAccX = fDiffX * fRatio
fAccY = fDiffY * fRatio
_vx += fAccX
_vy += fAccY
_vx *= aParticles(iPos).friction
_vy *= aParticles(iPos).friction
_x += _vx
_y += _vy
If _x < 0 Then _x += iW
If _x > iW Then _x -= iW
If _y < 0 Then _y += iH
If _y > iH Then _y -= iH
aParticles(iPos).x = _x
aParticles(iPos).y = _y
aParticles(iPos).vx = _vx
aParticles(iPos).vy = _vy
End Sub
ScreenControl FB.SET_DRIVER_NAME, "GDI"
ScreenRes iW, iH, 32
Dim As String sTitle = "GDI Particles Mouse Attraction / Particles: " & iParticles & " / FPS: "
WindowTitle sTitle
Dim as HWND hHWND
ScreenControl(FB.GET_WINDOW_HANDLE, Cast(integer, hHWND))
Dim As HDC hDC = GetDC(hHWND)
Dim As BITMAPV5HEADER tBIV5HDR
tBIV5HDR.bV5Size = SizeOf(BITMAPV5HEADER)
tBIV5HDR.bV5Width = iW
tBIV5HDR.bV5Height = -iH
tBIV5HDR.bV5Planes = 1
tBIV5HDR.bV5BitCount = 32
tBIV5HDR.bV5Compression = BI_RGB
tBIV5HDR.bV5AlphaMask = &hFF000000
tBIV5HDR.bV5RedMask = &h00FF0000
tBIV5HDR.bV5GreenMask = &h0000FF00
tBIV5HDR.bV5BlueMask = &h000000FF
Dim As UInteger Ptr aBits
Dim As HBitmap hBitmapGDI
Dim As HDC hGfxDC
hBitmapGDI = CreateDIBSection(hDC, @tBIV5HDR, DIB_RGB_COLORS, @aBits, NULL, NULL)
hGfxDC = CreateCompatibleDC(hDC)
Var hObjOld = SelectObject(hGfxDC, hBitmapGDI)
Dim evt As EVENT
Dim As ULong iFPS = 0, i, iMPx = iW / 2, iMPy = iH / 2, iPos, iMax = iW * iH - 1
Dim fTimer As Double
For i = 0 To iParticles - 1
aParticles(i).x = Rnd() * iW
aParticles(i).y = Rnd() * iH
aParticles(i).friction = 0.975
aParticles(i).argb = &hFFFFFFFF
Next
fTimer = Timer
Do
BitBlt(hGfxDC, 0, 0, iW, iH, hGfxDC, 0, 0, BLACKNESS)
GetMouse(iMPx, iMPy)
For i = 0 To iParticles - 1
MoveParticles(iMPx, iMPy, i, 100)
iPos = Int(aParticles(i).x) + Int(aParticles(i).y) * iW
If iPos > iMax Then iPos = iMax
aBits[iPos] = aParticles(i).argb
Next
BitBlt(hDC, 0, 0, iW, iH, hGfxDC, 0, 0, SRCCOPY)
If Timer - fTimer > 1 Then
WindowTitle sTitle & iFPS
iFPS = 0
fTimer = Timer
EndIf
iFPS += 1
'If GetKey = 27 Then Exit Do
If (ScreenEvent(@evt)) Then
If evt.type = EVENT_WINDOW_CLOSE Or evt.type = SC_ESCAPE Then
SelectObject(hGfxDC, hObjOld)
ReleaseDC(hHWND, hDC)
DeleteDC(hGfxDC)
DeleteObject(hBitmapGDI)
Exit Do
EndIf
EndIf
Sleep(10)
Loop
Alles anzeigen
Der Code Aufbau sollte in beiden Sprachen relativ identisch sein (GDI). Die Exe starten und mit der Maus auf der GUI hin und her fahren.
Ergebnis:
Autoit @ 1000 Pixel: ~14 FPS
FB @ 25000 Pixel: ~64 FPS (limitiert, da Sleep verwendet wird)
Krass!
Runde2 -> Mandelbrot:
Au3:
;coded by UEZ build 2016-08-04
;idea taken from http://rosettacode.org/wiki/Mandelbrot_set#C.23 / JS version
#AutoIt3Wrapper_Compile_Both=y
#pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico")
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /pe /rm
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3"
#include <GUIConstantsEx.au3>
#include <WinAPIGdi.au3>
#include <WindowsConstants.au3>
AutoItSetOption("MouseCoordMode", 2)
AutoItSetOption("MustDeclareVars", 1)
Global $hGUI, $bExit
Global Const $iW = 1000, $iH = 600, $sTitle = "GDI Mandelbrot / Took "
AutoItSetOption("GUIOnEventMode", 1)
Global $iDetails = 100, $iDisplayFrequency = 100
Mandelbrot(-2, 1, -1, 1, $iDetails, $iDisplayFrequency)
AutoItSetOption("GUIOnEventMode", 0)
Func Mandelbrot($xmin, $xmax, $ymin, $ymax, $iterations, $iDisplayFrequency = 100)
$iDisplayFrequency = $iDisplayFrequency < 1 ? 1 : $iDisplayFrequency > $iH / 2 ? $iH / 2 : $iDisplayFrequency
$hGUI = GUICreate($sTitle & "...", $iW, $iH)
Local Const $hDC = _WinAPI_GetDC($hGUI)
Local $pBits, $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)
With $tBIV5HDR
.bV5Size = DllStructGetSize($tBIV5HDR)
.bV5Width = $iW
.bV5Height = -$iH
.bV5Planes = 1
.bV5BitCount = 32
.bV5Compression = $BI_BITFIELDS
.bV5RedMask = 0x00FF0000
.bV5GreenMask = 0x0000FF00
.bV5BlueMask = 0x000000FF
.bV5AlphaMask = 0xFF000000
EndWith
Local Const $hBitmapGDI = _WinAPI_CreateDIBSection($hDC, $tBIV5HDR, $DIB_RGB_COLORS, $pBits)
Global $tBitmap = DllStructCreate("uint px[" & $iW * $iH & "]", $pBits)
Local Const $hGfxDC = _WinAPI_CreateCompatibleDC($hDC)
Local Const $hObjOld = _WinAPI_SelectObject($hGfxDC, $hBitmapGDI)
GUISetState(@SW_SHOW, $hGUI)
$bExit = False
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Local $iX, $iY, $i, $ppos, $c, $x, $y
Local $fEnd, $fTimer = TimerInit()
For $iY = 0 To $iH - 1
For $iX = 0 To $iW - 1
$x = $xmin + ($xmax - $xmin) * $iX / ($iW - 1)
$y = $ymin + ($ymax - $ymin) * $iY / ($iH - 1)
$i = MandelIter($x, $y, $iterations)
$ppos = ($iW * $iY + $iX)
If ($i > $iterations) Then
$tBitmap.px(($ppos)) = 0xFF000000
Else
$c = 3 * Log($i) / Log($iterations - 1.0)
If ($c < 1) Then
$tBitmap.px(($ppos)) = 0xFF000000 + BitShift(Int(255 * $c), -16)
ElseIf ($c < 2) Then
$tBitmap.px(($ppos)) = 0xFF000000 + BitShift(255, -16) + BitShift(Int(255 * ($c - 1)), -8)
Else
$tBitmap.px(($ppos)) = 0xFFFFFF00 + (Int(255 * ($c - 2)))
EndIf
EndIf
Next
If Not Mod($iY, $iDisplayFrequency) Then
_WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $SRCCOPY)
ConsoleWrite(Round($iY / $iH * 100, 2) & "%" & @CRLF)
EndIf
Next
_WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $SRCCOPY)
$fEnd = TimerDiff($fTimer)
WinSetTitle($hGUI, "", $sTitle & $fEnd / 1000 & " seconds to render.")
Do
If $bExit Then ExitLoop
Until Not Sleep(100)
_WinAPI_SelectObject($hGfxDC, $hObjOld)
_WinAPI_ReleaseDC($hGUI, $hDC)
_WinAPI_DeleteDC($hGfxDC)
_WinAPI_DeleteObject($hBitmapGDI)
GUIDelete($hGUI)
EndFunc ;==>Mandelbrot
Func _Exit()
$bExit = True
EndFunc ;==>_Exit
Func MandelIter($cx, $cy, $maxIter)
Local $x = 0.0, $y, $xx, $yy, $xy, $i = $maxIter
While ($xx + $yy <= 4 And $i > 0)
$xy = $x * $y
$xx = $x * $x
$yy = $y * $y
$x = $xx - $yy + $cx
$y = $xy + $xy + $cy
$i -= 1
WEnd
Return $maxIter - $i
EndFunc ;==>MandelIter
Alles anzeigen
FB:
'coded by UEZ build 2016-08-04
'idea taken from http://rosettacode.org/wiki/Mandelbrot_set#C.23 / JS version
#include "windows.bi"
#include "fbgfx.bi"
Using FB
Declare Function mandelIter(cx As Single, cy As Single, maxIter As ULong) As ULong
Declare Sub Mandelbrot(xmin As Single, xmax As Single, ymin As Single, ymax As Single, iterations As ULong, iDisplayFrequency As ULong = 100)
Dim As Integer sW, sH
ScreenInfo(sW, sH)
Dim Shared As ULong iW, iH
iW = 1000 'Int(sW * 0.95)
iH = 600 'Int(sH * 0.90)
ScreenControl FB.SET_DRIVER_NAME, "GDI"
ScreenRes iW, iH, 24
Dim As String sTitle = "GDI Mandelbrot"
WindowTitle sTitle
Dim as HWND hHWND
ScreenControl(FB.GET_WINDOW_HANDLE, Cast(Integer, hHWND))
Dim Shared As HDC hDC
hDC = GetDC(hHWND)
Dim As BITMAPV5HEADER tBIV5HDR
tBIV5HDR.bV5Size = SizeOf(BITMAPV5HEADER)
tBIV5HDR.bV5Width = iW
tBIV5HDR.bV5Height = -iH
tBIV5HDR.bV5Planes = 1
tBIV5HDR.bV5BitCount = 32
tBIV5HDR.bV5Compression = BI_BITFIELDS
tBIV5HDR.bV5AlphaMask = &hFF000000
tBIV5HDR.bV5RedMask = &h00FF0000
tBIV5HDR.bV5GreenMask = &h0000FF00
tBIV5HDR.bV5BlueMask = &h000000FF
Dim Shared As ULong Ptr aBits
Dim As HBitmap hBitmapGDI
Dim Shared As HDC hGfxDC
hBitmapGDI = CreateDIBSection(hDC, @tBIV5HDR, DIB_RGB_COLORS, @aBits, NULL, NULL)
hGfxDC = CreateCompatibleDC(hDC)
Var hObjOld = SelectObject(hGfxDC, hBitmapGDI)
Dim evt As EVENT
Dim As ULong iFPS = 0, i, iMax = iW * iH - 1 , iX, iY, iARGB
Dim As Double fTimer, fEnd
fTimer = Timer
Mandelbrot(-2, 1, -1, 1, 5000, 100)
fEnd = Timer - fTimer
WindowTitle sTitle & " / Took " & fEnd & " seconds to render."
Do
If (ScreenEvent(@evt)) Then
Select Case evt.Type
Case SC_ESCAPE, EVENT_WINDOW_CLOSE
SelectObject(hGfxDC, hObjOld)
ReleaseDC(hHWND, hDC)
DeleteDC(hGfxDC)
DeleteObject(hBitmapGDI)
Exit Do
End Select
EndIf
Sleep(60)
Loop
Sub Mandelbrot(xmin As Single, xmax As Single, ymin As Single, ymax As Single, iterations As ULong, iDisplayFrequency As ULong = 100)
Dim As ULong i, ppos
Dim As Double c, x, y
Dim As ULong iX, iY
For iY = 0 To iH - 1
For iX = 0 To iW - 1
x = xmin + (xmax - xmin) * iX / (iW - 1)
y = ymin + (ymax - ymin) * iY / (iH - 1)
i = mandelIter(x, y, iterations)
ppos = (iW * iY + iX)
If (i > iterations) Then
aBits[ppos] = &hFF000000
Else
c = 3 * Log(i) / Log(iterations - 1.0)
If (c < 1) Then
aBits[ppos] = &hFF000000 + (Int(255 * c) Shl 16)
ElseIf ( c < 2 ) Then
aBits[ppos] = &hFF000000 + (255 Shl 16) + (Int(255 * (c - 1)) Shl 8)
Else
aBits[ppos] = &hFFFFFF00 + (Int(255 * (c - 2)))
EndIf
EndIf
Next
If iY Mod iDisplayFrequency = 0 Then BitBlt(hDC, 0, 0, iW, iH, hGfxDC, 0, 0, SRCCOPY)
Next
BitBlt(hDC, 0, 0, iW, iH, hGfxDC, 0, 0, SRCCOPY)
End Sub
Function mandelIter(cx As Single, cy As Single, maxIter As ULong) As ULong
Dim As Single x = 0.0, y, xx, yy, xy
Dim As ULong i = maxIter
While (xx + yy <= 4 And i > 0)
xy = x * y
xx = x * x
yy = y * y
x = xx - yy + cx
y = xy + xy + cy
i -= 1
Wend
Return maxIter - i
End Function
Alles anzeigen
AU3: ~107 Sekunden @100
FB: ~0.30 Sekunden @100, 1,7s @1000, 7,8s @5000 und 14,6s @10000.
Falls ihr Au3 mit $iDetails = 1000 ausprobieren wollt, dann macht euch vorher einen Kaffee, den ihr langsam und genüsslich trinken könnt oder falls ihr Raucher seid, dann raucht am besten eine dicke fette Zigarre
Runde3 -> GDI+ Performance Test:
Au3:
;coded by UEZ in 2016-08-05
#AutoIt3Wrapper_Compile_Both=y
#pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico")
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /pe /rm
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3"
#include <GDIPlus.au3>
Global Const $iW = 1000, $iH = 600, $sTitle = "GDI+ Performance Test / "
Global Const $hGUI = GUICreate($sTitle, $iW, $iH)
GUISetState()
_GDIPlus_Startup()
Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
Global Const $hPen = _GDIPlus_PenCreate(0xFF000000)
_GDIPlus_GraphicsClear($hCanvas)
Global $i, $fX1, $fY1, $fX2, $fY2, $iRounds = 20000
Global $fEnd, $fTimer = TimerInit()
For $i = 1 To $iRounds
$fX1 = Random() * $iW
$fX2 = Random() * $iW
$fY1 = Random() * $iH
$fY2 = Random() * $iH
_GDIPlus_PenSetColor($hPen, 0xFF000000 + Int(Random() * 0xFFFFFF))
_GDIPlus_GraphicsDrawLine($hCanvas, $fX1, $fY1, $fX2, $fY2, $hPen)
Next
$fEnd = TimerDiff($fTimer)
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hCanvas)
_GDIPlus_Shutdown()
WinSetTitle($hGUI, "", $sTitle & "Created " & $iRounds & " lines in " & Round($fEnd, 2) & " ms.")
Do
Until GUIGetMsg() = -3
Alles anzeigen
FB:
'coded by UEZ in 2016-08-05
#Include "win\gdiplus.bi"
#include "fbgfx.bi"
#include "windows.bi"
Using FB
Using GDIPLUS
Dim Shared As ULong iW, iH
iW = 1000
iH = 600
Dim As String sTitle = "GDI+ Performance Test / "
ScreenControl FB.SET_DRIVER_NAME, "GDI"
ScreenRes iW, iH, 32
WindowTitle sTitle
Dim evt As EVENT
Dim as HWND hHWND
ScreenControl(FB.GET_WINDOW_HANDLE, Cast(Integer, hHWND))
'_GDIPlus_Startup()
Dim GDIPlusStartupInput As GDIPLUSSTARTUPINPUT
Dim As ULONG_PTR GDIPlusToken
GDIPlusStartupInput.GdiplusVersion = 1
If (GdiplusStartup(@GDIPlusToken, @GDIPlusStartupInput, NULL) <> 0) Then
Print "FAILED TO INIT GDI+!"
EndIf
Dim As Any Ptr hCanvas, hPen
GdipCreateFromHWND(hHWND, @hCanvas) '_GDIPlus_GraphicsCreateFromHWND($hGUI)
GdipSetSmoothingMode(hCanvas, 4) '_GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
GdipCreatePen1(&hFF000000, 1, 2, @hPen) '_GDIPlus_PenCreate(0xFF000000)
GdipGraphicsClear(hCanvas, &hFF000000) '_GDIPlus_GraphicsClear($hCanvas)
Dim As Single fX1, fY1, fX2, fY2
Dim As ULong iRounds = 20000, i
Dim As Double fEnd, fTimer
fTimer = Timer 'TimerInit()
For i = 1 To iRounds
fX1 = Rnd() * iW
fX2 = Rnd() * iW
fY1 = Rnd() * iH
fY2 = Rnd() * iH
GdipSetPenColor(hPen, &hFF000000 + Int(Rnd() * &hFFFFFF)) '_GDIPlus_PenSetColor($hPen, 0xFF000000 + Int(Random() * 0xFFFFFF))
GdipDrawLine(hCanvas, hPen, fX1, fY1, fX2, fY2) '_GDIPlus_GraphicsDrawLine($hCanvas, $fX1, $fY1, $fX2, $fY2, $hPen)
Next
fEnd = (Timer - fTimer) * 1000 'TimerDiff($fTimer) -> FB counts in seconds not in ms!
GdipDeletePen(hPen) '_GDIPlus_PenDispose($hPen)
GdipDeleteGraphics(hCanvas) '_GDIPlus_GraphicsDispose($hCanvas)
GdiplusShutdown(GDIPlusToken) '_GDIPlus_Shutdown()
WindowTitle sTitle & "Created " & iRounds & " lines in " & fEnd & " ms."
Do
'something like GUIGetMsg()
If (ScreenEvent(@evt)) Then
Select Case evt.Type
Case SC_ESCAPE, EVENT_WINDOW_CLOSE
Exit Do
End Select
EndIf
Sleep(30)
Loop
Alles anzeigen
Au3: ca. 16,9 Sekunden
FB: ca. 14,5 Sekunden
Im Anhang die Source Codes + kompilierte Exes.
FB gefällt mir immer mehr...
Weitere Bespiele:
Battle GDI vs GDI+: Battle: Autoit vs. FreeBasic - Runde 1+2+3
Animated Pythagoras Tree in GDI / GDI+ / OpenGL: Battle: Autoit vs. FreeBasic - Runde 1+2+3
GDI Particle Repulsion Grid in GDI: Battle: Autoit vs. FreeBasic - Runde 1+2+3