Nasal library/debug: Difference between revisions

Jump to navigation Jump to search
→‎print_rank(): Finish doc
(Start print_rank())
(→‎print_rank(): Finish doc)
Line 199: Line 199:
{{Nasal doc
{{Nasal doc
|syntax = debug.print_rank(label, list, names);
|syntax = debug.print_rank(label, list, names);
|text = Formats and prints results from {{func link|rank()|page=this}}.
|text = Formats and prints results from {{func link|rank()|page=this}}. It will show them in order of fastest to slowest, the time taken in milliseconds, and what percentage of time each took relative to the slowest.
|param1 = label
|param1 = label
|param1text = Label to add to the results header.
|param1text = Label to add to the results header.
Line 205: Line 205:
|param2text = Results vector from {{func link|rank()|page=this}}.
|param2text = Results vector from {{func link|rank()|page=this}}.
|param3 = names
|param3 = names
|param3text = Either a vector or hash that will supply the names of the functions. If a hash, it must have the structure of <code>{ name: func, ... }</code>. If a vector, its structure can be etiher <code>[[name, func], ...]</code> or <code>[[func, name], ...]</code>
|param3text = Either a vector or hash that will supply the names of the functions. If a hash, it must have the structure of <code>{ name: func, ... }</code>. If a vector, its structure can be either <code><nowiki>[[name, func], ...]</nowiki></code> or <code><nowiki>[[func, name], ...]</nowiki></code>
|example1 =  
|example1 = var getElev = func(){
    var pos = geo.aircraft_position();
    return geo.elevation(pos.lat(), pos.lon());
}
var getTime = func(){
    return getprop("/sim/time/gmt");
}
var list = [getElev, getTime];
var result = debug.rank(list, 1000);
var names = [["getElev", getElev], ["getTime", getTime]];
#var names = [[getElev, "getElev"], [getTime, "getTime"]]; # other option
#var names = { # third option
#    "getElev": getElev,
#    "getTime": getTime
#};
debug.print_rank("getElev() and getTime()", result, names);
}}
}}


Navigation menu