The InterOp library is not optimized for speed. Nonetheless, the user should be aware of certain downsides to using the SWIG interface to C# (or any other language).
SWIG Binding Performance
The C# unit tests include a PerformanceTest.cs. This file shows three ways to simply sum all the focus scores for the first channel over >5 million entries.
The PerformanceTest.cs class demonstrates three different ways of summing focus scores:
2. Direct Call 1
The main loop in is C#
3. Direct Call 2
The main loop in is C#
1. Indirect Call
One loop in C++ One loop in C#
Results
The following table summarizes the results (the times are a single sample for illustrative purposes)
Test Name | Time (s) |
---|---|
Direct Call 1 | 38 |
Direct Call 2 | 45 |
Indirect Call | < 1 |
The results show that everytime we make a call from the native language to C++, we pay a hefty price. In many applications, this is a price we are willing to pay. However, for those applications where performance is a concern, it pays to add methods like copy_focus
, which limit the number of times we have to jump between C# (or another language) and C++.