GetElapsed(start, end) { if (end < start) { return (cellmax - start) + (end - cellmin); } else { return end - start; } } // Usage: new v = GetTickCount(); for (new i = 0; i < 1000000; i++) {} printf("Elapsed: %d", GetElapsed(v, GetTickCount()));