ev3dev/ev3dev-lang — pull request #25 by dsharlet (2014-12-25 10:02:33+00:00)
Title: Added LRU cache of fstream objects.

Hi ev3dev, first of all, thanks for putting together an awesome set of tools. This is exactly what I was hoping to find!

This PR implements a small cache of file handles for the C++ language bindings. This is discussed in issue #12. This is important to me because I'm trying to build some pretty stiff controllers. In this situation, the lower the latency (and higher the sample rate) the better.

I think that the cache should hopefully alleviate the concerns mentioned in discussion on #12 regarding caching file handles consuming too many OS resources. The global LRU cache guarantees that there will only be < FILE_CACHE_SIZE file handles open at once. I think that this PR should basically make the cases that care about performance faster (reading/writing a few attributes very frequently in a tight loop) and

I benchmarked a program that reads the same attribute repeatedly in a tight loop:

Uncached:

real 0m16.823s
user 0m5.850s
sys 0m9.750s

Cached:

real 0m2.842s
user 0m1.610s
sys 0m1.100s