I don't know if this is actually how it's supposed to be calculated. But since Scratch's "wait () seconds" block seemingly isn't affected by lag, a loop based timer can count how many times it loops per every real second. Any lag will slow the loop timer, but not the real second timer. This does seem to correlate with how scratch runs at ~30 frames per second (without input), so it works I guess.