Check out Modern Chess, our featured variant for January, 2025.


[ Help | Earliest Comments | Latest Comments ]
[ List All Subjects of Discussion | Create New Subject of Discussion ]
[ List Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]

Single Comment

Game Courier Developer's Guide. Learn how to design and program Chess variants for Game Courier.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Tue, Aug 4, 2020 02:13 AM UTC:

Here's a result I find surprising. First the code I ran:

def countdown fn countdown dec #0 onlyif #0;
def coontduwn fn coontduwn dec #a onlyif #a =a;
sub countdown cnt:
  if #cnt:
    return sub countdown dec #cnt;
  else:
    return #0;
  endif;
endsub;
stopwatch reset;
print fn countdown 10000;
stopwatch;
stopwatch reset;
print fn coontduwn 10000;
stopwatch;
stopwatch reset;
gosub countdown 1000;
stopwatch;
stopwatch reset;
set a 10000;
do while #a:
  dec a;
loop;
print #a;
stopwatch;

Then the results:

0

Elapsed time: 0.12341594696045 seconds

0

Elapsed time: 0.14718699455261 seconds

Elapsed time: 0.50130391120911 seconds

0

Elapsed time: 0.17237901687622 seconds

The first two tests show that function recursion is slightly faster with native subroutine variables instead of with user variables. That's not surprising, because there is more overhead in using user variables.

It's also not surprising that function recursion is faster than subroutine recursion. Though I do wonder why it's by such a high margin. I had to reduce the countdown by a factor of 10 just to test subroutine recursion speed, and it still took more time than function recursion. While using a user variable may be a factor, it is even slower than the coontduwn function that uses user variables.

What is surprising is the last result, which shows that a do loop was slower than function recursion. The countdown is the same, but the loop took more time.