SHD-WebsiteFingerprintingLab/part3/worker.js

36 lines
842 B
JavaScript

// Number of sweep counts
// TODO (Exercise 3-1): Choose an appropriate value!
let P = 1000;
// Number of elements in your trace
let K = 5 * 1000 / P;
// Array of length K 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(K);
// 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-1): Record data for 5 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") {
setTimeout(record, 0);
}
};