fb:porticula NoPaste
Vergleich Singelthread - Dualthread
Uploader: | Volta |
Datum/Zeit: | 29.11.2007 12:01:50 |
Dim Shared threadsync As Any Ptr
Dim Shared thread1handle As Any Ptr
Dim Shared thread2handle As Any Ptr
Type rng
ystart As Integer
ymax As Integer
End Type
Screen 19, 8
Sub Main (ByRef yrng As rng)
Dim As Integer X, Y, Count
Dim As Single Size, R, I, RTmp, Rs, Iss
Dim As Byte Ptr img = ImageCreate(800,1) ' eine Zeile
For Y = yrng.ystart To yrng.ymax
For X = 32 To 832-1'Trick statt img[X+32]
Count = 600
Size = 0
R = 0
I = 0
While Size < 4 And Count > 0
RTmp = R
Rs = R * R
Iss = I * I
R = Rs - Iss + ((X - 650) / 320)
I = (2 * RTmp * I) + ((Y - 300) / 320)
Size = Rs + Iss
Count -= 1
Wend
img[X]= (count Mod 256)
Next
MutexLock threadsync
Put (0,Y), img, pset
MutexUnlock threadsync
Next
ImageDestroy img
End Sub
Dim As Double t1, t2, its1, its2
Dim As rng rng0, rng1, rng2
threadsync = MutexCreate
rng0.ystart = 0
rng0.ymax = 600-1
t1 = Timer
thread1handle = ThreadCreate(Cast(Any Ptr,@Main), @rng0)
ThreadWait(thread1handle)
t2 = Timer
its1 = (800* 600) / (t2 - t1)
Sleep 1000
Cls
rng1.ystart = 0
rng1.ymax = 300-1
rng2.ystart = 300
rng2.ymax = 600-1
t1 = Timer
thread1handle = ThreadCreate(Cast(Any Ptr,@Main), @rng1)
thread2handle = ThreadCreate(Cast(Any Ptr,@Main), @rng2)
ThreadWait(thread1handle)
ThreadWait(thread2handle)
t2 = Timer
its2 = (800* 600) / (t2 - t1)
MutexDestroy(threadsync)
Locate 1,1:Print "SINGLE Thread (pixel/sec): " & its1
Locate 2,1:Print "Dual Thread (pixel/sec) : " & its2
Locate 3,1:Print "Acceleration : " & (Int((its2/its1)*100) /100) & "fach"
Sleep