PDA

View Full Version : Benchmarking script



ErosOlmi
08-08-2006, 12:16
Do you have some spare time to write some scripts in order to test thinBasic speed execution? In different areas like: pure execution speed, user data usage, functions and recursion, graphics, math, ...

We need to have some scripts in order to test thinBasic speed evolution from version to version.
Script, if you agree, will be distributed with thinBasic setup.

You can get some examples installing thinBasic and looking at the following examples:
thinBasic\SampleScripts\BugZapper\BugZapper.tbasicc
thinBasic\SampleScripts\General\Speed\

If you need more functions to measure time, please let us know.

Regards
Eros

Petr Schreiber
15-08-2006, 20:54
Hi Eros,

hard to decide which benchmarking technique is the right one, but sorting of any type is always interesting.

In the following code, the built-in ARRAY SORT proves it's qualities, and the rest are hand written bubble sorts, which try to sort out array of DOUBLEs, LONGs and STRINGs.

As Bubble sort seems to be one of the slowest sorting ( after manual :) ), they could be indicators of any parsing speed, ... improvements.

The numeric arrays are always filled with values from maximal to minimal and the sort algo tries to achieve minimal to maximal order.

Here is the code:


' Bubble Sorting benchmark

MsgBox 0, "This is benchmark to measure speed of sorting data", %MB_ICONINFORMATION, "Bubble Sort Benchmark"

%MAXDIM = 1000

dim ResultString as string = "Results for benchmark ( sorting"+STR$(%MAXDIM)+" items )"+$CRLF+$CRLF+"( times in miliseconds )"+$CRLF+$CRLF

dim VarArray1Orig(%MAXDIM) as double
dim VarArray2Orig(%MAXDIM) as long
dim StrArray1Orig(%MAXDIM) as string
dim ResultCount as long

dim i, j, x as long

dim t1 as quad, t2 as quad

' Built in
GenerateRandomData
t1 = GetTickCount
Array sort VarArray1Orig(), ascend
t2 = GetTickCount
ResultString += "Built in sorting :"+STR$((t2-t1))+$CRLF
ShowResults

' Bubble sort for doubles
GenerateRandomData
t1 = GetTickCount
for i = %MAXDIM to 1 step -1
for j = 2 to i
if VarArray1Orig(j-1) > VarArray1Orig(j) then Swap VarArray1Orig(j-1), VarArray1Orig(j)
next
next
t2 = GetTickCount
ResultString += "Bubble sort ( DOUBLEs ) :"+$TAB+STR$((t2-t1))+$CRLF
ShowResults

' Bubble sort for longs
GenerateRandomData
t1 = GetTickCount
for i = %MAXDIM to 1 step -1
for j = 2 to i
if VarArray2Orig(j-1) > VarArray2Orig(j) then Swap VarArray2Orig(j-1), VarArray2Orig(j)
next
next
t2 = GetTickCount
ResultString += "Bubble sort ( LONGs ) :"+$TAB+STR$((t2-t1))+$CRLF
ShowResults

' Bubble sort for strings
GenerateRandomData
t1 = GetTickCount

for i = %MAXDIM to 1 step -1
for j = 2 to i
if StrArray1Orig(j-1) > StrArray1Orig(j) then swap StrArray1Orig(j-1), StrArray1Orig(j)
next
next

t2 = GetTickCount
ResultString += "Bubble sort ( STRINGs ) :"+$TAB+STR$((t2-t1))+$CRLF+$CRLF+"Benchmark has ended... "
ShowResults

' Useful stuff

function GenerateRandomData()
local i as long
dim stringv as long
for i = 1 to %MAXDIM
VarArray1Orig(i) = %MAXDIM-i
VarArray2Orig(i) = %MAXDIM-i
incr stringv
if stringv > 255 then stringv = 0
StrArray1Orig(i) = repeat$(255, CHR$(stringv))
next
end function

function ShowResults()
msgbox 0, ResultString, %MB_ICONINFORMATION, "thinBASIC benchmark"


Bye,
Petr

kryton9
27-07-2007, 06:19
I found this site with benchmarks and the code to do them. These are for compiled programs, so probably not fair, but thought I should link it as he does have the code used for the benchmarks if it helps. What is neat it is for upcoming languages like F# using C# as the control. Interesting to see the number of lines needed and times, they do vary quite a bit.

http://strangelights.com/blog/archive/2007/06/17/1588.aspx