Skip to content

Performance comparison of loops

Julius Paffrath edited this page Sep 11, 2018 · 5 revisions

In this chapter I will share some performance comparison results. I was interested how runtime performance is influenced by different ways to run code multiple times in jask.

Generally there are three different options to achieve loops in jask: run loops, while loops and the call operator. The following samples all produces the same results:

run loop

run i from 0 to 1000000 with i plus 1
    printLine(i)
endrun

while loop

store 0 in i

while i smaller 1000000
    printLine(i)
    increment i
endrun

call operator

store 0 in i

function run()
    printLine(!i)
    increment !i
end

call run() 1000000 times

To get more precise results, I executed all three ways on the same machine to a counter of 1.000.000. Every execution ran in its own context. The execution times are the arithmetic averages of ten executions:

  • run loop: 19.551 seconds
  • while loop: 17.984 seconds
  • call operator: 28.125 seconds

As you might expect, the call operator was the slowest, because function executions are very expensive. The while loop was slightly faster than the run loop.