NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

Sometimes the loop is 17 instructions, other times it's 25 instructions, without changing the loop code.

have you tried to make these vars volatile so the compiler would not optimize?