A few hours ago when reading the article I was also intrigued by the question and journeyed down a similar path regarding the moving window and the trade-offs. After toying with a couple of improper solutions I came to a very similar conclusion. The basic idea being that each time increment() is called, you store the difference since the last increment, and to count you simply add up the offsets until you reach your desired time limit. Anyway I emailed myself the basic idea to post here later. There are probably some obvious optimizations but it satisfied me as a solution. Pseudocodish javascript example below:
var second = 100000000
, minute = second * 60
, hour = minute * 60
, day = hour * 24
, current = 0
, lastIncrement = 0
, increments = [];
function increment(){
current = timer.time();
increments.push( current - lastIncrement );
lastIncrement = current;
}
function getCountInLastSecond(){
var copy = increments.slice()
, total = 0
, count = 0;
while( ( total <= second ) && ( amount = copy.pop() ) ){
total += amount;
count++;
}
return count;
}