Page 1 of 1
SortArray Micro Bench (for fun)
Posted: Sat Jul 04, 2015 6:58 pm
by Simo_na
Code: Select all
EnableExplicit
Global Dim test.i(15000),n.i,r.i,stime.i,etime.i,num.i=15000,Text_0,j.i,Text_1,String_0,Event
OpenWindow(#PB_Any, 40, 40, 225, 90, "SortArray Micro Bench")
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, "Wait...")
stime = ElapsedMilliseconds()
For j =1 To num
r= Random(num*10)
test (n) = r
n+1
Next
SortArray(test(), #PB_Sort_Ascending )
For n =0 To num-1
RandomizeArray(test())
SortArray(test(), #PB_Sort_Ascending )
Next
etime = ElapsedMilliseconds()-stime
DisableGadget(Text_0, 1)
Text_1 = TextGadget(#PB_Any, 28, 35, 100, 25, "Milliseconds")
String_0 = StringGadget(#PB_Any, 120, 25, 80, 40, Str (etime))
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
EndSelect
Until Event = #PB_Event_CloseWindow

Re: SortArray Micro Bench (for fun)
Posted: Sat Jul 04, 2015 10:42 pm
by Simo_na
Floating version
Code: Select all
EnableExplicit
Global Dim test.f(15000),n.i,r.i,stime.i,etime.i,num.i=5500,Text_0,j.i,Text_1,String_0,Event,cnt.i,flt.f=3.14
OpenWindow(#PB_Any, 40, 40, 225, 90, "SortArray Micro Bench")
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, "Wait...")
stime = ElapsedMilliseconds()
For j =1 To num
r=Random(num*25)
test(n)=r*flt
n+1
Next
For n =0 To num-1
SortArray(test(), #PB_Sort_Descending)
RandomizeArray(test())
SortArray(test(), #PB_Sort_Ascending)
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, Str(num-1) + " -> "+Str(n))
cnt+1
If cnt>1000
While WindowEvent(): Wend
cnt=0
EndIf
Next
etime = ElapsedMilliseconds()-stime
DisableGadget(Text_0, 1)
Text_1 = TextGadget(#PB_Any, 28, 35, 100, 25, "Milliseconds")
String_0 = StringGadget(#PB_Any, 120, 25, 80, 40, Str (etime))
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
EndSelect
Until Event = #PB_Event_CloseWindow
Re: SortArray Micro Bench (for fun)
Posted: Sun Jul 05, 2015 9:02 am
by User_Russian
Your code creates a lot of gadgets. I fixed the bug.
Code: Select all
EnableExplicit
Global Dim test.f(15000),n.i,r.i,stime.i,etime.i,num.i=5500,Text_0,j.i,Text_1,String_0,Event,cnt.i,flt.f=3.14
OpenWindow(#PB_Any, 40, 40, 225, 90, "SortArray Micro Bench")
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, "Wait...")
DisableDebugger
stime = ElapsedMilliseconds()
For j =1 To num
r=Random(num*25)
test(n)=r*flt
n+1
Next
For n =0 To num-1
SortArray(test(), #PB_Sort_Descending)
RandomizeArray(test())
SortArray(test(), #PB_Sort_Ascending)
If n%100=0 Or n=num
SetGadgetText(Text_0, Str(num-1) + " -> "+Str(n))
While WindowEvent(): Wend
EndIf
Next
etime = ElapsedMilliseconds()-stime
EnableDebugger
DisableGadget(Text_0, 1)
Text_1 = TextGadget(#PB_Any, 28, 35, 100, 25, "Milliseconds")
String_0 = StringGadget(#PB_Any, 120, 25, 80, 40, Str (etime))
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
EndSelect
Until Event = #PB_Event_CloseWindow
Re: SortArray Micro Bench (for fun)
Posted: Sun Jul 05, 2015 9:28 am
by Simo_na
ok
added a little bit improved math float
Code: Select all
EnableExplicit
DisableDebugger
Global Dim test.f(15000),n.i,r.i,stime.i,etime.i,num.i=5500,Text_0,j.i,Text_1,String_0,Event,cnt.i,flt.f=3.14159,nind.i=32768*100,EventID
OpenWindow(#PB_Any, 40, 40, 225, 90, "SortArray Micro Bench")
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, "Wait...")
stime = ElapsedMilliseconds()
For j =1 To num
r=Random(num*25)
test(n)=(Tan(flt)+(r*flt)/Sin(flt))/nind
n+1
Next
For n =0 To num-1
SortArray(test(), #PB_Sort_Descending)
RandomizeArray(test())
SortArray(test(), #PB_Sort_Ascending)
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, Str(num-1) + " -> "+Str(n))
cnt+1
If cnt>1000
While WindowEvent(): Wend
cnt=0
EndIf
Next
etime = ElapsedMilliseconds()-stime
DisableGadget(Text_0, 1)
Text_1 = TextGadget(#PB_Any, 28, 35, 100, 25, "Milliseconds")
String_0 = StringGadget(#PB_Any, 120, 25, 80, 40, Str (etime))
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
Re: SortArray Micro Bench (for fun)
Posted: Sun Jul 05, 2015 9:40 am
by User_Russian
Simo_na wrote:ok
But in your new code, the exact same bug!
It creates a lot of gadgets.
Code: Select all
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, Str(num-1) + " -> "+Str(n))
Re: SortArray Micro Bench (for fun)
Posted: Sun Jul 05, 2015 2:50 pm
by Simo_na
sorry
Code: Select all
EnableExplicit
DisableDebugger
Global Dim test.f(15001),n.i,r.i,stime.i,etime.i,num.i=15000,Text_0,j.i,Text_1,String_0,Event,cnt.i,flt.f=3.14159,nind.i=32768*100,EventID
OpenWindow(#PB_Any, 40, 40, 225, 90, "SortArray Micro Bench")
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, "Wait...")
stime = ElapsedMilliseconds()
For j =1 To num
r=Random(num*25)
test(n)=(Tan(flt)+(r*flt)/Sin(flt))/nind
n+1
Next
For n =0 To num-1
SortArray(test(), #PB_Sort_Descending)
RandomizeArray(test())
SortArray(test(), #PB_Sort_Ascending)
cnt+1
If cnt>1000
Text_0 = TextGadget(#PB_Any, 5, 5, 100, 25, Str(num-1) + " -> "+Str(n))
While WindowEvent(): Wend
cnt=0
EndIf
Next
etime = ElapsedMilliseconds()-stime
DisableGadget(Text_0, 1)
Text_1 = TextGadget(#PB_Any, 28, 35, 100, 25, "Milliseconds")
String_0 = StringGadget(#PB_Any, 120, 25, 80, 40, Str (etime))
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
Re: SortArray Micro Bench (for fun)
Posted: Sun Jul 05, 2015 11:42 pm
by Simo_na
ok
Code: Select all
EnableExplicit
DisableDebugger
Global Dim test.f(15001),n.i,r.i,stime.i,etime.i,num.i=15000,j.i
Global Text_1,String_0,Event,cnt.i,flt.f=0.69314718055994529,nind.f=9792.5885,EventID
OpenWindow(#PB_Any, 40, 40, 225, 90, "SortArray Micro Bench")
stime = ElapsedMilliseconds()
For j =1 To num
r=Random(num*25)
test(n)=Sqr((Tan(flt)+(r*flt)/Sin(flt))/(nind*flt))
n+1
Next
Text_1 = TextGadget(#PB_Any, 5, 5, 150, 25, "")
For n =0 To num-1
SortArray(test(), #PB_Sort_Descending)
RandomizeArray(test())
SortArray(test(), #PB_Sort_Ascending)
cnt+1
If cnt>1000
SetGadgetText(Text_1,StrF(test(n))+Chr(13)+Str(num-1)+" -> "+Str(n))
While WindowEvent(): Wend
cnt=0
EndIf
Next
etime = ElapsedMilliseconds()-stime
SetGadgetText(Text_1,"")
Text_1 = TextGadget(#PB_Any, 28, 35, 100, 25, "Milliseconds")
String_0 = StringGadget(#PB_Any, 120, 25, 80, 40, Str (etime))
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow