Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
zichun
Newbie


Joined: 07 Sep 2004
Posts: 2

PostPosted: Fri Sep 10, 2004 1:18 pm   

slow script...
 
I've once enquired about how slow zMud parses its script, and understand that this is due to zMud having to convert a string to a number type, perform arithmethic calculations, and convert it back to string again. However, I realized that the slowness is not only local to arithmetic calculations, but even to string handling. This may be due to bad scripting on my part, so I would need your advice.

Take a script which converts $123456 to $1,234,567 for example:

zMud Script:

Code:

#alias GenAddCommasSub {
#var GenReturnVal {}
#var GenLoop 0
#loop %len( %-1),1 {
  #if (@GenLoop==3) {
    #if (%i==1) {#if (%isnumber( %copy( %-1, %i, 1))) {#var GenReturnVal {,@GenReturnVal}} {#var GenReturnVal {@GenReturnVal}}} {
      #var GenLoop 1
      #var GenReturnVal {,@GenReturnVal}
      }
    } {#ADD GenLoop 1}
  #var GenReturnVal {%copy( %-1, %i, 1)@GenReturnVal}
  }
#unvar GenTmpPos
#unvar GenLoop
#var GenReturnVal {%trim( @GenReturnVal)}
}


A simple benchmark of:
Code:

 #echo START!
 #loop (1,3) {GenAddCommasSub 5555555}
 #echo END!


takes around 4 seconds, which is rather ridiculous (for converting just 3 values).

On the other hand, a same alias on MudMaster:
Code:

/ALIAS {GenAddCommasSub %9} {
/VAR {GenReturnVal}{ }{ZGeneric};
/VAR {GenTmpPos}{@Len($9)};/VAR {GenLoop}{0};
/WHILE {$GenTmpPos>0}{
/MATH {GenTmpPos}{$GenTmpPos-1};
/IF {$GenLoop=3}{
       /IF {$GenTmpPos==0}{
              /IF {@IsNumber(@Mid($9,$GenTmpPos,1))}{
                     /VAR {GenReturnVal}{,$GenReturnVal}{ZGeneric}
              }{/VAR {GenReturnVal}{$GenReturnVal}{ZGeneric}}
       }{
              /MATH {GenLoop}{1};/VAR {GenReturnVal}{,$GenReturnVal}{ZGeneric}
       }
}{/MATH {GenLoop}{$GenLoop+1} };
/VAR {GenReturnVal}{@Mid($9,$GenTmpPos,1)$GenReturnVal}};/UNVAR {GenTmpPos};/UNVAR {GenLoop};
/VAR {GenReturnVal}{@RTrim($GenReturnVal)}{ZGeneric}}


took negligible time at all to parse /loop (1,100) {GenAddCommasSub 5555555}. (note that zMud’s loop is from 1 to 3 while mud-master is from 1 to 100!)

Another 2 questions I'd like to raise pertaining to scripting is whether zMud supports multi-dimensional (or at least 2-d) arrays, and whether zMud has a function to return the unix timestamp (no of seconds since epoch).

Thanks in advance,
zichun
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Sep 10, 2004 3:15 pm   
 
Sorry, but it takes me under a second to do your loop 100 times in zMUD (0.563 seconds). You must have a VERY SLOW computer if it takes you over four seconds to do three loops.

Yes, your alias is clumsy. This one's a little better (0.250 seconds for 100 loops).
Code:
#AL Commas {
 #VAR GenReturnVal %1
 #LOOP %len( %1),1 {
  #IF ((%len( %1) - %i)\3 = 2) {#VAR GenReturnVal %insert( ",", @GenReturnVal, %i)}
 }
 #IF (%len( %1)\3 = 0) {#VAR GenReturnVal %remove( ",", @GenReturnVal)}
}

2-dimensional arrays? You mean record variables maybe? See the entry for #ADDKEY.

I can think of no reason that a Windows program should provide UNIX values. zMUD does have several functions and system variables to supply time values. I'm sure that anyone who actually needs to know the number of seconds since "epoch" (whenever that is), can find a way to produce the number.

Since you apparently prefer MudMaster to zMUD, go ahead and use it. Nobody here will be offended, in fact we don't even need to know. None of us will seek out MudMaster forums to belittle its performance. zMUD is able to stand on its own without trolling.

EDIT: Revised alias/time per hundred loops

_________________
LightBulb
Former MudMaster user
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Fri Sep 10, 2004 9:04 pm   
 
Quote:
Take a script which converts $123456 to $1,234,567 for example:

Why write a full script for something that zmud already has a function for


#say %format( "&.0n", %1)

THAT is instantaneous No variables no Loops Can Mudmaster top the speed of that. *horns*
Also combined with a #SUB or #PSUB it can be used to format to your hearts content.

Looping through 100 big Random numbers in under half a second
#loop 1,100 {#say %format( "&.0n", %random(10000000,1000000000000000000))}

Hell looping through that 1000 times takes 2 seconds and thats just cause it has to display it :P
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
lindy
Newbie


Joined: 11 Sep 2004
Posts: 3

PostPosted: Sat Sep 11, 2004 6:59 am   
 
Quote:
Since you apparently prefer MudMaster to zMUD, go ahead and use it. Nobody here will be offended, in fact we don't even need to know. None of us will seek out MudMaster forums to belittle its performance. zMUD is able to stand on its own without trolling.


From the sidelines, I think zichun's intention of posting is anything but to "troll"...

As a paying user for zMUD, it is understandable that one would have cause for concern if, while (appearantly) converting scripts from Mudmaster to zMUD, the scripts take overly long to execute it becomes impractical for usage purposes...

I personally do not sense any hostility in his original post, it seems to be that he just wants to know if there is a better way of getting it done.

Quote:
Another 2 questions I'd like to raise pertaining to scripting is whether zMud supports multi-dimensional


Record seems to be hardly able to handle multidimensional arrays beyond 2-d.. My idea would be to use a single list and then do some math to locate the desired element within...

so if you're looking for element [0][2][1] in a 3-d array (and there are 3 elements per dimension), you would do something like @psuedoArray.%eval(0 x 3x3 + 2 * 3 + 1)... although I imagine the Settings Editor might lag out or crash even when you click on the variable if each dimension holds something like 52 elements each... since that will result in a list with 52^3, or 140608 elements...


Quote:
zMUD does have several functions and system variables to supply time values. I'm sure that anyone who actually needs to know the number of seconds since "epoch" (whenever that is), can find a way to produce the number.


The unix "epoch" refers to January 1 1970 00:00:00 GMT. It provides programmers a handy way (and phpBB uses it too for that matter) to represent time down to seconds, and also an effective way to calculate the time elasped between two points in time (such as phpBB's message purging feature which deletes inactive threads after a set amount of days... in the SQL query, it can simply delete all posts whose timestamp is less than current_timestamp-inactive_posts_threshold_in_seconds).
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net