sub sieve(n)
flags = CreateObject("roArray", 8192 + 1, true)
count = 0
while n > 0
n = n - 1
count = 0
for i = 2 to 8192
flags[i] = true
end for
for i = 2 to 8192
if (flags[i])
' remove all multiples of prime: i
for k = i + i to 8192 step i
flags[k] = false
end for
count = count + 1
end if
end for
end while
end sub
sub RunBenchmarks()
benchmarks = {sieve:100}
screen = CreateObject("roParagraphScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetTitle("Benchmark Suite")
screen.AddButton(1, "Close")
screen.Show()
dialog = CreateObject("roOneLineDialog")
dialog.SetTitle("Running benchmarks ...")
dialog.ShowBusyAnimation()
dialog.Show()
for each benchmark in benchmarks
value = benchmarks[benchmark]
dialog.SetTitle("Running benchmark " + benchmark + "(" + Stri(value) + ") ...")
st = UpTime(0)
Eval(benchmark + "(" + Stri(value) + ")")
et = UpTime(0)
screen.AddHeaderText(benchmark + "(" + Stri(value) + "): " + Str(et-st))
end for
dialog.Close()
closed = false
' event loop
while true
msg = wait(0, port) ' wait for an event
if type(msg) = "roParagraphScreenEvent"
if msg.isButtonPressed()
buttonIndex = msg.GetIndex()
if buttonIndex = 1
exit while
end if
else if msg.isScreenClosed()
exit while
end if
end if
end while
screen.Close()
end sub
sub DisplayMainScreen()
screen = CreateObject("roParagraphScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetTitle("Benchmark Suite")
screen.AddButton(1, "Start")
screen.AddButton(2, "Close")
screen.Show()
' event loop
while true
msg = wait(0, port) ' wait for an event
if type(msg) = "roParagraphScreenEvent"
if msg.isButtonPressed()
buttonIndex = msg.GetIndex()
if buttonIndex = 1
RunBenchmarks()
else
exit while
end if
else if msg.isScreenClosed()
exit while
end if
end if
end while
screen.Close()
' anytime all screens within a channel are closed, the channel will exit
end sub
sub Main()
DisplayMainScreen()
end sub
sub bench(n)
end sub
sub sieve(n)
flags = CreateObject("roArray", 8192 + 1, true)
count = 0
while n > 0
n = n - 1
count = 0
for i = 2 to 8192
flags[i] = true
end for
for i = 2 to 8192
if (flags[i])
' remove all multiples of prime: i
for k = i + i to 8192 step i
flags[k] = false
end for
count = count + 1
end if
end for
end while
end sub
sub integerAssignmentOperator(n%)
r% = 1%
for i% = 1% to n%
r% = i%
end for
end sub
sub integerArithmeticAdditionOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% + i%
end for
end sub
sub integerArithmeticSubtractOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% - i%
end for
end sub
sub integerArithmeticMultiplicationOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% * i%
end for
end sub
sub integerArithmeticDivisionOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% / i%
end for
end sub
sub integerArithmeticExponentiationOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% ^ i%
end for
end sub
sub integerUnaryPlusOperator(n%)
r% = 1%
for i% = 1% to n%
r% = +i%
end for
end sub
sub integerUnaryNegationOperator(n%)
r% = 1%
for i% = 1% to n%
r% = -i%
end for
end sub
sub integerComparisonLessThanOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% < i%
end for
end sub
sub integerComparisonGreaterThanOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% > i%
end for
end sub
sub integerComparisonLessThanOrEqualToOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% <= i%
end for
end sub
sub integerComparisonGreaterThanOrEqualToOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% >= i%
end for
end sub
sub integerComparisonEqualToOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% = i%
end for
end sub
sub integerComparisonNotEqualToOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% <> i%
end for
end sub
sub integerBitwiseAndOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% and i%
end for
end sub
sub integerBitwiseOrOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% or i%
end for
end sub
sub integerBitwiseNegationOperator(n%)
for i% = 1% to n%
r% = not i%
end for
end sub
sub floatAssignmentOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = i!
end for
end sub
sub floatArithmeticAdditionOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! + i!
end for
end sub
sub floatArithmeticSubtractOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! - i!
end for
end sub
sub floatArithmeticMultiplicationOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! * i!
end for
end sub
sub floatArithmeticDivisionOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! / i!
end for
end sub
sub floatArithmeticExponentiationOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! ^ i!
end for
end sub
sub floatUnaryPlusOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = +i!
end for
end sub
sub floatUnaryNegationOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = -i!
end for
end sub
sub floatComparisonLessThanOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! < i!
end for
end sub
sub floatComparisonGreaterThanOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! > i!
end for
end sub
sub floatComparisonLessThanOrEqualToOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! <= i!
end for
end sub
sub floatComparisonGreaterThanOrEqualToOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! >= i!
end for
end sub
sub floatComparisonEqualToOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! = i!
end for
end sub
sub floatComparisonNotEqualToOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! <> i!
end for
end sub
sub floatBitwiseAndOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! and i!
end for
end sub
sub floatBitwiseOrOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! or i!
end for
end sub
sub floatBitwiseNegationOperator(n!)
for i! = 1.0! to n!
r! = not i!
end for
end sub
sub doubleAssignmentOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = i#
end for
end sub
sub doubleArithmeticAdditionOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# + i#
end for
end sub
sub doubleArithmeticSubtractOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# - i#
end for
end sub
sub doubleArithmeticMultiplicationOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# * i#
end for
end sub
sub doubleArithmeticDivisionOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# / i#
end for
end sub
sub doubleArithmeticExponentiationOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# ^ i#
end for
end sub
sub doubleUnaryPlusOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = +i#
end for
end sub
sub doubleUnaryNegationOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = -i#
end for
end sub
sub doubleComparisonLessThanOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# < i#
end for
end sub
sub doubleComparisonGreaterThanOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# > i#
end for
end sub
sub doubleComparisonLessThanOrEqualToOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# <= i#
end for
end sub
sub doubleComparisonGreaterThanOrEqualToOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# >= i#
end for
end sub
sub doubleComparisonEqualToOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# = i#
end for
end sub
sub doubleComparisonNotEqualToOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# <> i#
end for
end sub
sub doubleBitwiseAndOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# and i#
end for
end sub
sub doubleBitwiseOrOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# or i#
end for
end sub
sub doubleBitwiseNegationOperator(n#)
for i# = 1.0# to n#
r# = not i#
end for
end sub
sub logicalAndOperator(n)
for i = 1 to n
b = i > 5 and i < 7
end for
end sub
sub logicalOrOperator(n)
for i = 1 to n
b = i < 5 or i > 7
end for
end sub
sub booleanAssignmentOperator(n)
r = false
for i = 1 to n
r = true
end for
end sub
sub booleanLogicalNegationOperator(n)
r = false
for i = 1 to n
r = not r
end for
end sub
sub stringConcatenationOperator(n)
r$ = ""
for i = 1 to n
r$ = r$ + "."
end for
end sub
sub stringComparisonLessThanOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ < Stri(i%)
end for
end sub
sub stringComparisonGreaterThanOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ > Stri(i%)
end for
end sub
sub stringComparisonLessThanOrEqualToOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ <= Stri(i%)
end for
end sub
sub stringComparisonGreaterThanOrEqualToOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ >= Stri(i%)
end for
end sub
sub stringComparisonEqualToOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ = Stri(i%)
end for
end sub
sub stringComparisonNotEqualToOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ <> Stri(i%)
end for
end sub
sub referenceComparisonEqualToOperator(n)
roa = CreateObject("roAssociativeArray")
rol = CreateObject("roList")
for i% = 1% to n%
b = roa = rol
end for
end sub
sub referenceComparisonNotEqualToOperator(n)
roa = CreateObject("roAssociativeArray")
rol = CreateObject("roList")
for i = 1 to n
b = roa <> rol
end for
end sub
function RunBenchmarks()
benchmarks = [
["bench",1],
["sieve",100],
["integerAssignmentOperator",100],
["integerArithmeticAdditionOperator",100],
["integerArithmeticSubtractOperator",100],
["integerArithmeticMultiplicationOperator",100],
["integerArithmeticDivisionOperator",100],
["integerArithmeticExponentiationOperator",100],
["integerUnaryPlusOperator",100],
["integerUnaryNegationOperator",100],
["integerComparisonLessThanOperator",100],
["integerComparisonGreaterThanOperator",100],
["integerComparisonLessThanOrEqualToOperator",100],
["integerComparisonGreaterThanOrEqualToOperator",100],
["integerComparisonEqualToOperator",100],
["integerComparisonNotEqualToOperator",100],
["integerBitwiseAndOperator",100],
["integerBitwiseOrOperator",100],
["integerBitwiseNegationOperator",100],
["floatAssignmentOperator",100],
["floatArithmeticAdditionOperator",100],
["floatArithmeticSubtractOperator",100],
["floatArithmeticMultiplicationOperator",100],
["floatArithmeticDivisionOperator",100],
["floatArithmeticExponentiationOperator",100],
["floatUnaryPlusOperator",100],
["floatUnaryNegationOperator",100],
["floatComparisonLessThanOperator",100],
["floatComparisonGreaterThanOperator",100],
["floatComparisonLessThanOrEqualToOperator",100],
["floatComparisonGreaterThanOrEqualToOperator",100],
["floatComparisonEqualToOperator",100],
["floatComparisonNotEqualToOperator",100],
["floatBitwiseAndOperator",100],
["floatBitwiseOrOperator",100],
["floatBitwiseNegationOperator",100],
["doubleAssignmentOperator",100],
["doubleArithmeticAdditionOperator",100],
["doubleArithmeticSubtractOperator",100],
["doubleArithmeticMultiplicationOperator",100],
["doubleArithmeticDivisionOperator",100],
["doubleArithmeticExponentiationOperator",100],
["doubleUnaryPlusOperator",100],
["doubleUnaryNegationOperator",100],
["doubleComparisonLessThanOperator",100],
["doubleComparisonGreaterThanOperator",100],
["doubleComparisonLessThanOrEqualToOperator",100],
["doubleComparisonGreaterThanOrEqualToOperator",100],
["doubleComparisonEqualToOperator",100],
["doubleComparisonNotEqualToOperator",100],
["doubleBitwiseAndOperator",100],
["doubleBitwiseOrOperator",100],
["doubleBitwiseNegationOperator",100],
["logicalAndOperator",100],
["logicalOrOperator",100],
["booleanAssignmentOperator",100],
["booleanLogicalNegationOperator",100],
["stringConcatenationOperator",100],
["stringComparisonLessThanOperator",100],
["stringComparisonGreaterThanOperator",100],
["stringComparisonLessThanOrEqualToOperator",100],
["stringComparisonGreaterThanOrEqualToOperator",100],
["stringComparisonEqualToOperator",100],
["stringComparisonNotEqualToOperator",100],
["referenceComparisonEqualToOperator",100],
["referenceComparisonNotEqualToOperator",100]
]
dialog = CreateObject("roOneLineDialog")
port = CreateObject("roMessagePort")
dialog.SetMessagePort(port)
dialog.SetTitle("Running ...")
dialog.ShowBusyAnimation()
dialog.Show()
print "Running Benchmark Suite"
tt = 0
text = ""
for each benchmark in benchmarks
print "Running Benchmark: " + benchmark[0] + "(" + Stri(benchmark[1]) + ") ..."
st = UpTime(0)
Eval(benchmark[0] + "(" + Stri(benchmark[1]) + ")")
et = UpTime(0)
t = et-st
tt = tt + t
print "Elapsed Time: " + benchmark[0] + "(" + Stri(benchmark[1]) + "): " + Str(t) + " s"
end for
print "Total Elapsed Time: " + str(tt) " s"
dialog.Close()
return tt
end function
sub DisplayRunScreen()
screen = CreateObject("roParagraphScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetTitle("Benchmark Suite")
screen.AddButton(1, "Close")
screen.Show()
tt = RunBenchmarks()
screen.AddHeaderText("Elapsed Time: " + Str(tt) + "s")
' event loop
while true
msg = wait(0, port) ' wait for an event
if type(msg) = "roParagraphScreenEvent"
if msg.isButtonPressed()
buttonIndex = msg.GetIndex()
if buttonIndex = 1
exit while
end if
end if
if msg.isScreenClosed()
exit while
end if
end if
end while
screen.Close()
end sub
sub DisplayMainScreen()
screen = CreateObject("roParagraphScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetTitle("Benchmark Suite")
screen.AddButton(1, "Start")
screen.AddButton(2, "Close")
screen.Show()
' event loop
while true
msg = wait(0, port) ' wait for an event
if type(msg) = "roParagraphScreenEvent"
if msg.isButtonPressed()
buttonIndex = msg.GetIndex()
if buttonIndex = 1
DisplayRunScreen()
else if buttonIndex = 2
exit while
end if
end if
if msg.isScreenClosed()
exit while
end if
end if
end while
screen.Close()
end sub
sub Main()
DisplayMainScreen()
end sub
ok here is todays benchmark suite
i want to thank the members who helped me with the questions that i posted... teamwork help save me time trying to figure it out...
ive adds all builtin functions
tomorrow i'll try to get to statements, joy 😉
finally, i'm running it on my old roku xd, the roku 2 xs just reboots cause of use of double as for-loop variable, i think...
anyways, hopefully the woku 2 xs will soon get a fix and i will be able to compare the two boxes
finally, if anyone has a roku 1 please run the benchmarks
im getting on my roku xs total elapsed time
237.8598 s
237.7297 s
235.6101 s
most of which are consumed by 100 calls to sieve...
what do you get.... does it even work, or crashes, if crashes, let me know details can be found in debug console port 8085...
benchmark_suite.brs
sub bench(n)
end sub
sub sieve(n)
flags = CreateObject("roArray", 8192 + 1, true)
count = 0
while n > 0
n = n - 1
count = 0
for i = 2 to 8192
flags[i] = true
end for
for i = 2 to 8192
if (flags[i])
' remove all multiples of prime: i
for k = i + i to 8192 step i
flags[k] = false
end for
count = count + 1
end if
end for
end while
end sub
sub integerAssignmentOperator(n%)
r% = 1%
for i% = 1% to n%
r% = i%
end for
end sub
sub integerArithmeticAdditionOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% + i%
end for
end sub
sub integerArithmeticSubtractOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% - i%
end for
end sub
sub integerArithmeticMultiplicationOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% * i%
end for
end sub
sub integerArithmeticDivisionOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% / i%
end for
end sub
sub integerArithmeticExponentiationOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% ^ i%
end for
end sub
sub integerUnaryPlusOperator(n%)
r% = 1%
for i% = 1% to n%
r% = +i%
end for
end sub
sub integerUnaryNegationOperator(n%)
r% = 1%
for i% = 1% to n%
r% = -i%
end for
end sub
sub integerComparisonLessThanOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% < i%
end for
end sub
sub integerComparisonGreaterThanOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% > i%
end for
end sub
sub integerComparisonLessThanOrEqualToOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% <= i%
end for
end sub
sub integerComparisonGreaterThanOrEqualToOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% >= i%
end for
end sub
sub integerComparisonEqualToOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% = i%
end for
end sub
sub integerComparisonNotEqualToOperator(n%)
r% = 1%
for i% = 1% to n%
b = r% <> i%
end for
end sub
sub integerBitwiseAndOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% and i%
end for
end sub
sub integerBitwiseOrOperator(n%)
r% = 1%
for i% = 1% to n%
r% = r% or i%
end for
end sub
sub integerBitwiseNegationOperator(n%)
for i% = 1% to n%
r% = not i%
end for
end sub
sub floatAssignmentOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = i!
end for
end sub
sub floatArithmeticAdditionOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! + i!
end for
end sub
sub floatArithmeticSubtractOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! - i!
end for
end sub
sub floatArithmeticMultiplicationOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! * i!
end for
end sub
sub floatArithmeticDivisionOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! / i!
end for
end sub
sub floatArithmeticExponentiationOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! ^ i!
end for
end sub
sub floatUnaryPlusOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = +i!
end for
end sub
sub floatUnaryNegationOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = -i!
end for
end sub
sub floatComparisonLessThanOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! < i!
end for
end sub
sub floatComparisonGreaterThanOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! > i!
end for
end sub
sub floatComparisonLessThanOrEqualToOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! <= i!
end for
end sub
sub floatComparisonGreaterThanOrEqualToOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! >= i!
end for
end sub
sub floatComparisonEqualToOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! = i!
end for
end sub
sub floatComparisonNotEqualToOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
b = r! <> i!
end for
end sub
sub floatBitwiseAndOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! and i!
end for
end sub
sub floatBitwiseOrOperator(n!)
r! = 1.0!
for i! = 1.0! to n!
r! = r! or i!
end for
end sub
sub floatBitwiseNegationOperator(n!)
for i! = 1.0! to n!
r! = not i!
end for
end sub
sub doubleAssignmentOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = i#
end for
end sub
sub doubleArithmeticAdditionOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# + i#
end for
end sub
sub doubleArithmeticSubtractOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# - i#
end for
end sub
sub doubleArithmeticMultiplicationOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# * i#
end for
end sub
sub doubleArithmeticDivisionOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# / i#
end for
end sub
sub doubleArithmeticExponentiationOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# ^ i#
end for
end sub
sub doubleUnaryPlusOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = +i#
end for
end sub
sub doubleUnaryNegationOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = -i#
end for
end sub
sub doubleComparisonLessThanOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# < i#
end for
end sub
sub doubleComparisonGreaterThanOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# > i#
end for
end sub
sub doubleComparisonLessThanOrEqualToOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# <= i#
end for
end sub
sub doubleComparisonGreaterThanOrEqualToOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# >= i#
end for
end sub
sub doubleComparisonEqualToOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# = i#
end for
end sub
sub doubleComparisonNotEqualToOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
b = r# <> i#
end for
end sub
sub doubleBitwiseAndOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# and i#
end for
end sub
sub doubleBitwiseOrOperator(n#)
r# = 1.0#
for i# = 1.0# to n#
r# = r# or i#
end for
end sub
sub doubleBitwiseNegationOperator(n#)
for i# = 1.0# to n#
r# = not i#
end for
end sub
sub logicalAndOperator(n)
for i = 1 to n
b = i > 5 and i < 7
end for
end sub
sub logicalOrOperator(n)
for i = 1 to n
b = i < 5 or i > 7
end for
end sub
sub booleanAssignmentOperator(n)
r = false
for i = 1 to n
r = true
end for
end sub
sub booleanLogicalNegationOperator(n)
r = false
for i = 1 to n
r = not r
end for
end sub
sub stringConcatenationOperator(n)
r$ = ""
for i = 1 to n
r$ = r$ + "."
end for
end sub
sub stringComparisonLessThanOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ < Stri(i%)
end for
end sub
sub stringComparisonGreaterThanOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ > Stri(i%)
end for
end sub
sub stringComparisonLessThanOrEqualToOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ <= Stri(i%)
end for
end sub
sub stringComparisonGreaterThanOrEqualToOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ >= Stri(i%)
end for
end sub
sub stringComparisonEqualToOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ = Stri(i%)
end for
end sub
sub stringComparisonNotEqualToOperator(n)
r$ = "45"
for i% = 1% to n%
b = r$ <> Stri(i%)
end for
end sub
sub referenceComparisonEqualToOperator(n)
roa = CreateObject("roAssociativeArray")
rol = CreateObject("roList")
for i% = 1% to n%
b = roa = rol
end for
end sub
sub referenceComparisonNotEqualToOperator(n)
roa = CreateObject("roAssociativeArray")
rol = CreateObject("roList")
for i = 1 to n
b = roa <> rol
end for
end sub
sub CreateObjectFunction(n)
for i = 1 to n
r = CreateObject("roList")
end for
end sub
sub integerTypeFunction(n)
for i = 1 to n
r = Type(5%)
end for
end sub
sub floatTypeFunction(n)
for i = 1 to n
r = Type(5.0!)
end for
end sub
sub doubleTypeFunction(n)
for i = 1 to n
r = Type(5.0#)
end for
end sub
sub booleanTypeFunction(n)
for i = 1 to n
r = Type(true)
end for
end sub
sub stringTypeFunction(n)
for i = 1 to n
r = Type("my string")
end for
end sub
sub referenceTypeFunction(n)
o = CreateObject("roList")
for i = 1 to n
r = Type(o)
end for
end sub
sub GetGlobalAAFunction(n)
for i = 1 to n
r = GetGlobalAA()
end for
end sub
sub integerBoxFunction(n)
for i = 1 to n
r = Box(5%)
end for
end sub
sub floatBoxFunction(n)
for i = 1 to n
r = Box(5.0!)
end for
end sub
sub doubleBoxFunction(n)
for i = 1 to n
r = Box(5.0#)
end for
end sub
sub booleanBoxFunction(n)
for i = 1 to n
r = Box(true)
end for
end sub
sub stringBoxFunction(n)
for i = 1 to n
r = Box("my string")
end for
end sub
sub referenceBoxFunction(n)
o = CreateObject("roList")
for i = 1 to n
r = Box(o)
end for
end sub
sub RunFunction(n)
for i = 1 to n
r = Run("pkg:/run_benchmark.test.brs", n)
end for
end sub
sub RunFunction2(n)
r = Run("pkg:/run_benchmark.test.brs")
for i = 1 to n
run_test(n)
end for
end sub
sub EvalFunction(n)
for i = 1 to n
r = Eval(n.toStr())
end for
end sub
sub GetLastRunCompileErrorFunction(n)
for i = 1 to n
r = GetLastRunCompileError()
end for
end sub
sub GetLastRunRuntimeErrorFunction(n)
for i = 1 to n
r = GetLastRunRuntimeError()
end for
end sub
sub SleepFunction(n)
for i = 1 to n
r = Sleep(0)
end for
end sub
sub WaitFunction(n)
p = CreateObject("roMessagePort")
for i = 1 to n
r = Wait(1, p)
end for
end sub
sub GetInterfaceFunction(n)
o = CreateObject("roList")
for i = 1 to n
r = GetInterface(o, "ifList")
end for
end sub
sub UpTimeFunction(n)
for i = 1 to n
r = UpTime(0)
end for
end sub
' we should not run this test, it reboots the system
'sub RebootSystemFunction(n)
' for i = 1 to n
' r = RebootSystem()
' end for
'end sub
sub ListDirFunction(n)
for i = 1 to n
r = ListDir("pkg:/")
end for
end sub
sub WriteAsciiFileFunction(n)
for i = 1 to n
r = WriteAsciiFile("tmp:/benchmark_suite" + n.toStr() + ".tmp", n.toStr())
end for
end sub
sub ReadAsciiFileFunction(n)
for i = 1 to n
r = ReadAsciiFile("tmp:/benchmark_suite" + n.toStr() + ".tmp")
end for
end sub
sub CopyFileFunction(n)
for i = 1 to n
r = CopyFile("tmp:/benchmark_suite.tmp", "tmp:/benchmark_suite" + n.toStr() + ".tmp")
end for
end sub
sub MatchFilesFunction(n)
for i = 1 to n
r = MatchFiles("tmp:/", "*" + n.toStr() + ".tmp")
end for
end sub
sub DeleteFileFunction(n)
for i = 1 to n
r = DeleteFile("tmp:/benchmark_suite" + n.toStr() + ".tmp")
end for
end sub
sub CreateDirectoryFunction(n)
for i = 1 to n
r = CreateDirectory("tmp:/benchmark_suite" + n.toStr())
end for
end sub
sub DeleteDirectoryFunction(n)
for i = 1 to n
r = DeleteDirectory("tmp:/benchmark_suite" + n.toStr())
end for
end sub
' requires usb storage
'sub FormatDriveFunction(n)
' for i = 1 to n
' r = FormatDrive("", "FAT32")
' end for
'end sub
sub strtoiFunction(n)
for i = 1 to n
r = strtoi("1")
end for
end sub
sub RunGarbageCollectorFunction(n)
for i = 1 to n
r = RunGarbageCollector()
end for
end sub
sub UCaseFunction(n)
for i = 1 to n
r = UCase("test")
end for
end sub
sub LCaseFunction(n)
for i = 1 to n
r = LCase("test")
end for
end sub
sub AscFunction(n)
for i = 1 to n
r = Asc("a")
end for
end sub
sub ChrFunction(n)
for i = 1 to n
r = Chr(35)
end for
end sub
sub InstrFunction(n)
for i = 1 to n
r = Instr(1, "this is a test", "is")
end for
end sub
sub LeftFunction(n)
for i = 1 to n
r = Left(1, "this is a test", 3)
end for
end sub
sub LenFunction(n)
for i = 1 to n
r = Len(1, "this is a test")
end for
end sub
sub MidFunction(n)
for i = 1 to n
r = Mid(1, "this is a test", 4, 3)
end for
end sub
sub RightFunction(n)
for i = 1 to n
r = Right(1, "this is a test", 3)
end for
end sub
sub StrFunction(n)
for i = 1 to n
r = Str(1.0)
end for
end sub
sub StringFunction(n)
for i = 1 to n
r = String(10, "*")
end for
end sub
sub ValFunction(n)
str1 = "12"
str2 = "34"
for i = 1 to n
r = Val(str1 + "." + str2)
end for
end sub
sub AbsFunction(n)
for i = 1 to n
r = Abs(1.0)
end for
end sub
sub AtnFunction(n)
for i = 1 to n
r = Atn(1.0)
end for
end sub
sub CosFunction(n)
for i = 1 to n
r = Cos(1.0)
end for
end sub
sub CsngFunction(n)
for i = 1 to n
r = Csng(1)
end for
end sub
sub CdblFunction(n)
for i = 1 to n
r = Cdbl(1)
end for
end sub
sub ExpFunction(n)
for i = 1 to n
r = Exp(1.0)
end for
end sub
sub FixFunction(n)
for i = 1 to n
r = Fix(1.0)
end for
end sub
sub IntFunction(n)
for i = 1 to n
r = Int(1.0)
end for
end sub
sub LogFunction(n)
for i = 1 to n
r = Log(1.0)
end for
end sub
sub RndFunction(n)
for i = 1 to n
r = Rnd(0)
end for
end sub
sub integerRndFunction(n)
for i = 1 to n
r = Rnd(5)
end for
end sub
sub integerSgnFunction(n)
for i = 1 to n
r = Rnd(1)
end for
end sub
sub floatSgnFunction(n)
for i = 1 to n
r = Sgn(1.0)
end for
end sub
sub SinFunction(n)
for i = 1 to n
r = Sin(1.0)
end for
end sub
sub SqrFunction(n)
for i = 1 to n
r = Sqr(1.0)
end for
end sub
sub TanFunction(n)
for i = 1 to n
r = Tan(1.0)
end for
end sub
function RunBenchmarks()
benchmarks = [
["bench",1],
["sieve",100],
["integerAssignmentOperator",100],
["integerArithmeticAdditionOperator",100],
["integerArithmeticSubtractOperator",100],
["integerArithmeticMultiplicationOperator",100],
["integerArithmeticDivisionOperator",100],
["integerArithmeticExponentiationOperator",100],
["integerUnaryPlusOperator",100],
["integerUnaryNegationOperator",100],
["integerComparisonLessThanOperator",100],
["integerComparisonGreaterThanOperator",100],
["integerComparisonLessThanOrEqualToOperator",100],
["integerComparisonGreaterThanOrEqualToOperator",100],
["integerComparisonEqualToOperator",100],
["integerComparisonNotEqualToOperator",100],
["integerBitwiseAndOperator",100],
["integerBitwiseOrOperator",100],
["integerBitwiseNegationOperator",100],
["floatAssignmentOperator",100],
["floatArithmeticAdditionOperator",100],
["floatArithmeticSubtractOperator",100],
["floatArithmeticMultiplicationOperator",100],
["floatArithmeticDivisionOperator",100],
["floatArithmeticExponentiationOperator",100],
["floatUnaryPlusOperator",100],
["floatUnaryNegationOperator",100],
["floatComparisonLessThanOperator",100],
["floatComparisonGreaterThanOperator",100],
["floatComparisonLessThanOrEqualToOperator",100],
["floatComparisonGreaterThanOrEqualToOperator",100],
["floatComparisonEqualToOperator",100],
["floatComparisonNotEqualToOperator",100],
["floatBitwiseAndOperator",100],
["floatBitwiseOrOperator",100],
["floatBitwiseNegationOperator",100],
["doubleAssignmentOperator",100],
["doubleArithmeticAdditionOperator",100],
["doubleArithmeticSubtractOperator",100],
["doubleArithmeticMultiplicationOperator",100],
["doubleArithmeticDivisionOperator",100],
["doubleArithmeticExponentiationOperator",100],
["doubleUnaryPlusOperator",100],
["doubleUnaryNegationOperator",100],
["doubleComparisonLessThanOperator",100],
["doubleComparisonGreaterThanOperator",100],
["doubleComparisonLessThanOrEqualToOperator",100],
["doubleComparisonGreaterThanOrEqualToOperator",100],
["doubleComparisonEqualToOperator",100],
["doubleComparisonNotEqualToOperator",100],
["doubleBitwiseAndOperator",100],
["doubleBitwiseOrOperator",100],
["doubleBitwiseNegationOperator",100],
["logicalAndOperator",100],
["logicalOrOperator",100],
["booleanAssignmentOperator",100],
["booleanLogicalNegationOperator",100],
["stringConcatenationOperator",100],
["stringComparisonLessThanOperator",100],
["stringComparisonGreaterThanOperator",100],
["stringComparisonLessThanOrEqualToOperator",100],
["stringComparisonGreaterThanOrEqualToOperator",100],
["stringComparisonEqualToOperator",100],
["stringComparisonNotEqualToOperator",100],
["referenceComparisonEqualToOperator",100],
["referenceComparisonNotEqualToOperator",100],
["CreateObjectFunction",100],
["integerTypeFunction",100],
["floatTypeFunction",100],
["doubleTypeFunction",100],
["booleanTypeFunction",100],
["stringTypeFunction",100],
["referenceTypeFunction",100],
["GetGlobalAAFunction",100],
["integerBoxFunction",100],
["floatBoxFunction",100],
["doubleBoxFunction",100],
["booleanBoxFunction",100],
["stringBoxFunction",100],
["referenceBoxFunction",100],
["RunFunction",100],
["RunFunction2",100],
["EvalFunction",100],
["GetLastRunCompileErrorFunction",100],
["GetLastRunRuntimeErrorFunction",100],
["SleepFunction",100],
["WaitFunction",100],
["GetInterfaceFunction",100],
["UpTimeFunction",100],
'["RebootSystemFunction",100],
["ListDirFunction",100],
["WriteAsciiFileFunction",100],
["ReadAsciiFileFunction",100],
["CopyFileFunction",100],
["MatchFilesFunction",100],
["DeleteFileFunction",100],
["CreateDirectoryFunction",100],
["DeleteDirectoryFunction",100],
'["FormatDriveFunction",100],
["strtoiFunction",100],
["RunGarbageCollectorFunction",100],
["UCaseFunction",100],
["LCaseFunction",100],
["AscFunction",100],
["ChrFunction",100],
["InstrFunction",100],
["LeftFunction",100],
["LenFunction",100],
["MidFunction",100],
["RightFunction",100],
["StrFunction",100],
["StringFunction",100],
["ValFunction",100],
["AbsFunction",100],
["AtnFunction",100],
["CosFunction",100],
["CsngFunction",100],
["CdblFunction",100],
["ExpFunction",100],
["FixFunction",100],
["IntFunction",100],
["LogFunction",100],
["RndFunction",100],
["integerRndFunction",100],
["integerSgnFunction",100],
["floatSgnFunction",100],
["SinFunction",100],
["SqrFunction",100],
["TanFunction",100]
]
dialog = CreateObject("roOneLineDialog")
port = CreateObject("roMessagePort")
dialog.SetMessagePort(port)
dialog.SetTitle("Running ...")
dialog.ShowBusyAnimation()
dialog.Show()
print "Running Benchmark Suite"
tt = 0
text = ""
for each benchmark in benchmarks
print "Running Benchmark: " + benchmark[0] + "(" + Stri(benchmark[1]) + ") ..."
st = UpTime(0)
Eval(benchmark[0] + "(" + Stri(benchmark[1]) + ")")
et = UpTime(0)
t = et-st
tt = tt + t
print "Elapsed Time: " + benchmark[0] + "(" + Stri(benchmark[1]) + "): " + Str(t) + " s"
end for
print "Total Elapsed Time: " + str(tt) " s"
dialog.Close()
return tt
end function
sub DisplayRunScreen()
screen = CreateObject("roParagraphScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetTitle("Benchmark Suite")
screen.AddButton(1, "Close")
screen.Show()
tt = RunBenchmarks()
screen.AddHeaderText("Elapsed Time: " + Str(tt) + "s")
' event loop
while true
msg = wait(0, port) ' wait for an event
if type(msg) = "roParagraphScreenEvent"
if msg.isButtonPressed()
buttonIndex = msg.GetIndex()
if buttonIndex = 1
exit while
end if
end if
if msg.isScreenClosed()
exit while
end if
end if
end while
screen.Close()
end sub
sub DisplayMainScreen()
screen = CreateObject("roParagraphScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetTitle("Benchmark Suite")
screen.AddButton(1, "Start")
screen.AddButton(2, "Close")
screen.Show()
' event loop
while true
msg = wait(0, port) ' wait for an event
if type(msg) = "roParagraphScreenEvent"
if msg.isButtonPressed()
buttonIndex = msg.GetIndex()
if buttonIndex = 1
DisplayRunScreen()
else if buttonIndex = 2
exit while
end if
end if
if msg.isScreenClosed()
exit while
end if
end if
end while
screen.Close()
end sub
sub Main()
DisplayMainScreen()
end sub
run_benchmark_test.brs
sub run_test(n)
end sub
"kbenson" wrote:
associative array and list/array access is pretty horrendous (it you are trying to accomplish ops in a tight loop, e.g. trying to achieve 60fps in a came)
point = {
x: 100
y: 100
}
[...loop...]
newX = point.x + i
[...loop...]
x = 100
y = 100
[...loop...]
newX = x + i
[...loop...]
NAME COUNT TIME (s) AVE (us)
empty 1e+07 3.996 0.3996
ass_inv_lit 1e+07 2.602 0.2602
ass_bool_lit 1e+07 2.66 0.266
ass_int_lit 1e+07 3.311 0.3311
ass_flt_lit 1e+07 3.211 0.3211
ass_dbl_lit 100000 1.82004 18.2004
ass_str_l0_lit 1e+07 3.242 0.3242
ass_inv_var 1e+07 3.48 0.348
ass_bool_var 1e+07 3.479 0.3479
ass_int_var 1e+07 3.473 0.3473
ass_flt_var 1e+07 3.472 0.3472
ass_dbl_var 1e+06 6.7924 6.7924
ass_str_l0_var 1e+07 3.48 0.348
ass_inv_aa 50000 1.16202 23.2404
ass_inv_aa_l100 50000 1.18202 23.6404
ass_inv_aa_l1e4 50000 1.20402 24.0804
rd_inv_var 5e+06 1.735 0.347
rd_inv_aa 100000 1.07704 10.7704
rd_inv_aa_l100 100000 1.35504 13.5504
rd_inv_aa_l1e3 50000 2.14402 42.8804
rd_inv_aa_l1e4 5000 2.433002 486.6004
ass_inv_ar 100000 0.94604 9.4604
ass_inv_ar_l100 100000 0.95004 9.5004
ass_inv_ar_l1e4 100000 0.94404 9.4404
rd_inv_ar 100000 0.96004 9.6004
rd_inv_ar_l100 100000 1.03604 10.3604
rd_inv_ar_l1e3 100000 1.03304 10.3304
rd_inv_ar_l1e4 100000 1.04204 10.4204
ass_bool_aa 100000 2.43304 24.3304
ass_int_aa 100000 2.26804 22.6804
ass_flt_aa 100000 2.27404 22.7404
ass_dbl_aa 100000 2.79504 27.9504
ass_str_l0_aa 100000 2.32704 23.2704
accum_int 1e+06 1.0204 1.0204
accum_flt 1e+06 3.8064 3.8064
accum_dbl 100000 5.99804 59.9804
accum_str_len0 100000 3.71604 37.1604
sum_int 1e+06 1.0464 1.0464
sum_int_flt 1e+06 3.0754 3.0754
sum_int_dbl 100000 5.02604 50.2604
func_v_v 100000 1.86904 18.6904
func_v_b 100000 1.98904 19.8904
func_v_i 100000 2.08304 20.8304
func_v_f 100000 2.07804 20.7804
func_v_d 100000 4.49604 44.9604
func_v_s 100000 2.11104 21.1104
func_v_a 100000 9.98404 99.8404
func_v_o 100000 8.28404 82.8404
func_b_v 100000 2.04504 20.4504
func_b_b 100000 2.08104 20.8104
func_b_i 100000 2.14304 21.4304
func_b_f 100000 2.13504 21.3504
func_b_d 100000 4.56304 45.6304
func_b_s 100000 2.18604 21.8604
func_b_a 100000 10.14504 101.4504
func_b_o 100000 8.56504 85.6504
func_i_v 100000 2.11204 21.1204
func_i_b 100000 2.14804 21.4804
func_i_i 100000 2.16604 21.6604
func_i_f 100000 2.20304 22.0304
func_i_d 100000 4.63504 46.3504
func_i_s 100000 2.26304 22.6304
func_i_a 100000 10.35204 103.5204
func_i_o 100000 8.11904 81.1904
func_v_v_r 100000 1.87404 18.7404
func_b_b_r 100000 2.08504 20.8504
func_i_i_r 100000 2.19504 21.9504
func_f_f_r 100000 2.10204 21.0204
func_d_d_r 100000 5.48504 54.8504
func_s_s_r 100000 2.12004 21.2004
func_a_a_r 100000 10.44604 104.4604
func_o_o_r 100000 8.56804 85.6804
func_v_v 100000 1.93104 19.3104
func_o_v 100000 2.57004 25.7004
meth_v_v 100000 2.84704 28.4704
func_i_v 100000 2.12204 21.2204
func_o(i)_v 100000 2.48504 24.8504
meth_v(i)_v 100000 2.86304 28.6304
func_i_i 100000 2.19304 21.9304
func_o(i)_i 100000 3.87204 38.7204
meth_v(i)_i 100000 4.04804 40.4804
func_ii_v 100000 2.21304 22.1304
func_o(ii)_v 100000 2.48504 24.8504
meth_v(ii)_v 100000 2.77804 27.7804
func_ii_i_fk 100000 2.47004 24.7004
func_o(ii)_i_fk 100000 3.04404 30.4404
meth_v(ii)_i_fk 100000 3.39504 33.9504
func_ii_i 100000 2.46404 24.6404
func_a(ii)_i 100000 5.06404 50.6404
func_o(ii)_i 100000 5.08204 50.8204
meth_v(ii)_i 100000 5.12204 51.2204
func_iiiiiiiiii_i_fk 100000 3.57504 35.7504
func_a(iiiiiiiiii)_i_fk 100000 3.59704 35.9704
func_o(iiiiiiiiii)_i_fk 100000 3.51804 35.1804
meth_v(iiiiiiiiii)_i_fk 100000 3.85004 38.5004
func_iiiiiiiiii_i 100000 3.58704 35.8704
func_a(iiiiiiiiii)_i 10000 1.153004 115.3004
func_o(iiiiiiiiii)_i 10000 1.278004 127.8004
meth_v(iiiiiiiiii)_i 10000 1.284004 128.4004
func_ssssssssss_s 10000 2.415004 241.5004
func_a(ssssssssss)_s 10000 3.734004 373.4004
func_o(ssssssssss)_s 10000 3.742004 374.2004
meth_v(ssssssssss)_s 10000 3.816004 381.6004
func_dddddddddd_d 10000 5.760004 576.0004
func_a(dddddddddd)_d 10000 5.307004 530.7004
func_o(dddddddddd)_d 10000 5.215004 521.5004
meth_v(dddddddddd)_d 10000 5.214004 521.4004
sum_iiiiiiiiii_i_ass_fk 100000 0.63704 6.3704
sum_iiiiiiiiii_i_ass 100000 0.66804 6.6804
func_iiiiiiiiii_i_ass 100000 3.67104 36.7104
global_func_getglobalaa 100000 0.70817 7.0817
global_manual_globalobj 100000 3.98717 39.8717
global_func_getglobalaa_assign 100000 3.79117 37.9117
global_manual_globalobj_assign 100000 7.39917 73.9917
Testing complete.