Anyone written a way to calculate script execution time?

Has anyone come up with a clever way to track script execution time? Which is to say, calculate the difference between two times in Mafia?

This works fine, for output in one unit of time (seconds OR minutes OR hours), as long as that unit doesn't roll over during execution:
Code:
int start_time = now_to_string(format);
int end_time = now_to_string(format);
int elapsed_time = endtime - starttime;
... but it breaks if, for instance, end_time == 11h55m and end_time == 12h10m.

Anyone got a way to calculate it arbitrarily? Does Mafia have the ability to output the date in milliseconds?
 
I guess gametime_to_int() will output milliseconds. So I can do:
Code:
int start_time = gametime_to_int();
int end_time = gametime_to_int();
int elapsed_time = end_time - start_time;

For this purpose (calculating the difference), it doesn't really matter that this is in gametime, not localtime.
 
The "profile" CLI command looks like what you want.

Huh?

Code:
> profile

Unable to invoke

... Weird that it doesn't say "Unable to invoke profile". Clearly I'm doing something double-wrong.

Follow-up question: is there internal documentation for CLI commands? I know I can use ashref to get a full list of ash functions - is there a similar list of CLI commands? (I don't see "profile" on the wiki.)
 
I see. So "profile myscriptname" runs the script and then outputs details about its activity.

Which is really interesting! I'll have to run this against a few of my scripts and see if I can't get work out some efficiency improvements. But what I'm looking to do here is simply track the total execution time:

Code:
void main () {
    int start_time = now_to_string(format);

    do_some_stuff();

    int end_time = now_to_string(format);
    int elapsed_time = endtime - starttime;
}
 

heeheehee

Developer
Staff member
int gametime_to_int() looks like it returns milliseconds in the range {0, 1, ..., 86399999}. As long as your script doesn't run across rollovers, this should be adequate.
 
Top