Nasal library/debug: Difference between revisions

Jump to navigation Jump to search
→‎Functions: Doc benchmark_time()
(→‎benchmark(): Finish doc)
(→‎Functions: Doc benchmark_time())
Line 108: Line 108:


=== benchmark_time() ===
=== benchmark_time() ===
{{Nasal doc
|syntax = debug.benchmark_time(fn[, repeat[, output]]);
|text = Behaves in exactly the same way as {{func link|benchmark()|page=this}}, but returns the amount of time taken, rather than printing it out.
|param1 = fn
|param1text = Function to call.
|param2 = repeat
|param2text = Optional integer specifying how many times the function is to be run. If not given, the function will be run once.
|param3 = output
|param3text = Optional vector that will be returned with the return value of each function.
|example1 = var test = func(){
    var children = props.globals.getNode("sim").getChildren();
    var vec = [];
    foreach(var child; children){
        append(vec, child.getChildren());
    }
    return vec;
}
print(debug.benchmark_time(test));
|example2 = var test = func(){
    var children = props.globals.getNode("sim").getChildren();
    var vec = [];
    foreach(var child; children){
        append(vec, child.getChildren());
    }
    return vec;
}
print(debug.benchmark_time(test, 10));
|example3 = var test = func(){
    return getprop("/sim/time/gmt");
}
print(debug.benchmark_time(test, 1000, var res = []));
debug.dump(res);
}}
=== dump() ===
=== dump() ===
=== isnan() ===
=== isnan() ===

Navigation menu