Nasal performance and benchmarks: Difference between revisions

Jump to navigation Jump to search
add test descriptions and first results
m (→‎Articles: yet another one)
(add test descriptions and first results)
Line 7: Line 7:


= Benchmark add-on =
= Benchmark add-on =
The benchmark add-on will be published [https://sourceforge.net/p/flightgear/fgaddon/HEAD/tree/trunk/Addons/Benchmark here].
The benchmark add-on can be downloaded [https://sourceforge.net/p/flightgear/fgaddon/HEAD/tree/trunk/Addons/Benchmark here].
It is basically a collection of nasal snippets to be tested.
It is basically a collection of nasal snippets to be tested.  
A minimal GUI (menu item, simple dialog box) allows to start some benchmarks.
 
A benchmark test runs some function multiple time (repeat count) and measures the time taken (result).
The results of any benchmark is currently printed to the console, so you have to start FlightGear with console window to see this.
(The repeat count should be configurable via the GUI, this is on my to do list.)


= Performance analysis =
= Performance analysis =
== 2019-01 ==
Performance of Nasal snippets is tested by means of the Benchmark add-on which makes use of the debug.benchmark_time() function. The default repeat count for tests is 10000 (ten thousand). Depending on your hardware some tests may block your Flightgear many seconds. On Windows you may see the usual warnings about FlightGear not reacting any more.
to be written
In the next section available benchmarks are described. Test results follow below.
 
Results (time taken to complete a benchmark test) obviously depend on the hardware used, so the relevant information is not the absolute time but the ratio when comparing two code snippets.
Also, one should repeat benchmarks a couple of times and see if results are in the same order of magnitude. Benchmarks should be run only after FlightGear is fully ready, e.g. scenery and aircraft model loaded etc.
 
== currently available benchmarks ==
 
=== simpleClass ===
Object oriented programming (OOP, "programming with classes") gives several advantages (readability, re-usability and easier maintainance of code, to give just some examples) but might generate slightly slower code.
For most real-world cases this should be neglectible, nevertheless it is a simple, easy to understand test scenario.
 
<nowiki>
var simpleClass = {
    new: func {
        var obj = {
            parents: [simpleClass],
            value: 0,
        };
        return obj;
    },
   
    set: func(value) { me.value = value; },
    get: func { return me.value; },
};
 
var c = simpleClass.new();
 
var test_get_method = func {
    var x = c.get();
}
var test_get_direct = func {
    var x = c.value;
}
var test_set_method = func {
    c.set(1);
}
var test_set_direct = func {
    c.value = 1;
}
</nowiki>
 
=== property tree access ===
As the property tree is the central data exchange in FlightGear it is worth to know how to efficiently access it.
This benchmarks compares the getprop() agains the props.Node.getValue().
 
<nowiki>
var myprops = [];
var path = "/_benchmark/getprop/prop";
var test_getvalue = func {
    var test = 0;
    forindex (i; myprops) {
        t = myprops[i].getValue();
    }
}
var test_getprop = func {
    var test = 0;
    forindex (i; myprops) {
        t = getprop(path~i);
    }
}
var init = func {
    for (var i = 0; i < repeat; i += 1) {
        append(myprops, props.getNode(path~i, 1));
    }
}
printResult("test_getNode", debug.benchmark_time(init, 1));
printResult("test_getvalue", debug.benchmark_time(test_getvalue, 1));
printResult("test_getprop", debug.benchmark_time(test_getprop, 1));
</nowiki>
 
=== Canvas API - Text class ===
tbd


-->[[Category:Nasal]]
== Results 2019-01 ==


== References ==
=== simpleClass ===
Repeat count = 10000


=== Regression tests ===
Interpretation: using class methods is fine.
{| class="wikitable"
|-
! Test !! Time [s] !! Comment
|-
| get via class.get() || 0.015 ||
|-
| get via class.variable || 0.006 ||
|-
| set via class.set()|| 0.011 ||
|-
| set via class.variable || 0.004 ||
|}
 
=== Property access ===
Repeat count = 10000
 
It seems that any operation involving a property path (string) is relativly slow.
If you have to access a property more than once, e.g. in an update loop, you should create a props.Node object and use object.getValue().
 
{| class="wikitable"
|-
! Test !! Time [s] !! Comment
|-
| props.getNode() || 0.420 ||
|-
| node.getValue() || 0.010 || using a node object is 36-40 times faster
|-
| getprop() || 0.368 ||
|}
 
=== Canvas API - Text class ===
Optimized canvas API with caching and props.Node (not merged to FGDATA at the time of writing)
{| class="wikitable"
|-
! Test !! Time [s] !! Comment
|-
| setText() same value || 0.015 || old: 0.075
|-
| setText() different value || 0.100 || old: 0.150
|-
| appendText || 9.0 || the ~ operator is really slow
|}
 
[[Category:Nasal]]
 
= References =
 
== Regression tests ==
* [https://github.com/andyross/nasal/tree/master/misc original regression tests (Andy Ross)]
* [https://github.com/andyross/nasal/tree/master/misc original regression tests (Andy Ross)]


=== Articles ===
== Articles ==
* [[Howto:Canvas Path Benchmarking]]
* [[Howto:Canvas Path Benchmarking]]
* [[FlightGear Benchmark]]
* [[FlightGear Benchmark]]
Line 28: Line 153:
* [[Resource Tracking for FlightGear]]
* [[Resource Tracking for FlightGear]]


=== See also ===
== See also ==
 
* [[User:Philosopher/Nasal introspection]]
* [[User:Philosopher/Nasal introspection]]
* [[User:Philosopher/Optimization findings]]
* [[User:Philosopher/Optimization findings]]
246

edits

Navigation menu