You can store the timestamp of the last message of interest in a transaction-persistent variable - that is, an AVP or XAVP - using $TV():
Then, you can do some arithmetic like this to turn the difference between two timestamps into milliseconds. This is stolen straight from CSRP so adapt to your needs. :-)
# Log request processing time.
$var(cur_time) = $TV(Sn);
$var(proc_diff) = (
(((
$(var(cur_time){s.select,0,.}{s.int}) -
$(avp(proc_start){s.select,0,.}{s.int})
) * 1000000)
+
(
$(var(cur_time){s.select,1,.}{s.int}) -
$(avp(proc_start){s.select,1,.}{s.int})
) / 1000) mod 1000
);