>I suppose I could sum the counts and time deltas and update count and update count_ps, count and sum in one operation at the end.

That'll definitely make this code read easier.