SHD-WebsiteFingerprintingLab/part2/worker.js

33 lines
821 B
JavaScript
Raw Normal View History

2023-01-31 20:06:27 +00:00
// Duration of your trace, in milliseconds
let TRACE_LENGTH;
// Array of length TRACE_LENGTH with your trace's values
let T;
// Value of performance.now() when you started recording your trace
let start;
function record() {
// Create empty array for saving trace values
T = new Array(TRACE_LENGTH);
// Fill array with -1 so we can be sure memory is allocated
T.fill(-1, 0, T.length);
// Save start timestamp
start = performance.now();
// TODO (Exercise 3): Record data for TRACE_LENGTH seconds and save values to T.
// Once done recording, send result to main thread
postMessage(JSON.stringify(T));
}
// DO NOT MODIFY BELOW THIS LINE -- PROVIDED BY COURSE STAFF
self.onmessage = (e) => {
if (e.data.type === "start") {
TRACE_LENGTH = e.data.trace_length;
setTimeout(record, 0);
}
};