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 01:27 PM UTC in reply to Fergus Duniho from 02:13 AM:

Since the subroutine had a wrong variable name in it, I did it again and got slightly better results. First, the corrected code:

sub countdown cnt:
  if #cnt:
    return sub countdown dec #cnt;
  else:
    return #cnt;
  endif;
endsub;
stopwatch reset;
gosub countdown 1000;
stopwatch;

Then the result:

Elapsed time: 0.50052809715271 seconds

Trying again with var instead of #:

sub countdown cnt:
  if var cnt:
    return sub countdown dec var cnt;
  else:
    return var cnt;
  endif;
endsub;
stopwatch reset;
gosub countdown 1000;
stopwatch;

Elapsed time: 0.51695919036865 seconds

This slowed it down slightly. The curious thing is that #cnt calls evalvar() first, and this then calls getuservar(), whereas var cnt calls getuservar() directly. Based on this, I was expecting it to be faster. Factors that could explain the opposite result are #cnt is handled while parsing the line, while var cnt is handled by evaluating an expression, and var cnt is a longer string than #cnt, which means reading the line takes longer.

Trying var cnt with a function:

def countdown fn countdown dec var a onlyif var a =a;
stopwatch reset;
print fn countdown 10000;
stopwatch;

Elapsed time: 0.20279908180237 seconds

This also slowed things down, and it was by a lot more compared to the earlier result, which was 0.14718699455261. In the function for evaluating polish notation expressions, evaluation of prepended variables is handled before operators, but the extra line parsing shouldn't make as much of a difference, because the function definition is executed only once.