Currently time measurements for AVR boards (like my Mega2560) can be done using portInputRegister() what was mentioned somewhere as faster and better way tha using digitalRead(). It was also stated that reading the ports directly does not work properly on ESP8266.
To test and eventually (if working) use direct port reading for all boards.