-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjitter.cpp
More file actions
28 lines (19 loc) · 774 Bytes
/
jitter.cpp
File metadata and controls
28 lines (19 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector calculateResponseTime(NumericVector timestamps, NumericVector serviceTimes) {
NumericVector responseTimes(timestamps.size());
//Prime the pump
responseTimes[0] = serviceTimes[0];
for(int i=1; i<timestamps.size(); i++) {
double prevTimeOut = timestamps[i-1]+responseTimes[i-1];
double ts = timestamps[i];
double serviceTime = serviceTimes[i];
//We can't start processing this message until the previous one has left our system
double timeToStartProcessing = std::max(prevTimeOut, ts);
double timeOut = timeToStartProcessing + serviceTime;
//Calculate the final response time
responseTimes[i] = timeOut - ts;
}
return responseTimes;
}