Nasal library/debug: Difference between revisions

Jump to navigation Jump to search
→‎benchmark(): Finish doc
(Start benchmark())
(→‎benchmark(): Finish doc)
Line 67: Line 67:
{{Nasal doc
{{Nasal doc
|syntax = debug.benchmark(label, fn[, repeat[, output]]);
|syntax = debug.benchmark(label, fn[, repeat[, output]]);
|text =  
|text = Analyses the amount of time a function takes to run. If '''repeat''' is given and '''output''' is not, the time taken to repeat the function the given amount off times will be printed. If both are given, the return value of each repeat of the function will be returned in a vector '''output'''.
|param1 = label
|param1 = label
|param1text = Label to add to the output.
|param1text = Label to add to the output.
Line 73: Line 73:
|param2text = Function to call.
|param2text = Function to call.
|param3 = repeat
|param3 = repeat
|param3text =  
|param3text = Optional integer specifying how many times the function is to be run. If not given, the function will be run once.
|param4 = output
|param4 = output
|param4text =  
|param4text = Optional vector that will be returned with the return value of each function.
|example1 =  
|example1 = var test = func(){
    var children = props.globals.getNode("sim").getChildren();
    var vec = [];
    foreach(var child; children){
        append(vec, child.getChildren());
    }
    return vec;
}
var result = debug.benchmark("test()", test);
debug.dump(result);
|example2 = var test = func(){
    var children = props.globals.getNode("sim").getChildren();
    var vec = [];
    foreach(var child; children){
        append(vec, child.getChildren());
    }
    return vec;
}
debug.benchmark("test()", test, 10);
|example3 = var test = func(){
    var children = props.globals.getNode("sim").getChildren();
    var vec = [];
    foreach(var child; children){
        append(vec, child.getChildren());
    }
    return vec;
}
var result = debug.benchmark("test()", test, 10, []); # this example may cause a small pause
debug.dump(result);
}}
}}


Navigation menu