PulseIn function

Believe it or not, arduino will do better at these simple tasks than a full blown Linux. Thankfully, there are PRUs on the processor that are specifically made for this. That is what you need to look up.