SHD-WebsiteFingerprintingLab/part3/worker.js

36 lines
842 B
JavaScript
Raw Normal View History

2023-08-17 02:19:15 +00:00
// Number of sweep counts
2024-02-01 21:12:05 +00:00
// TODO (Exercise 3-1): Choose an appropriate value!
let P = 1000;
2023-01-31 20:06:27 +00:00
2023-08-17 02:19:15 +00:00
// Number of elements in your trace
let K = 5 * 1000 / P;
// Array of length K with your trace's values
2023-01-31 20:06:27 +00:00
let T;
// Value of performance.now() when you started recording your trace
let start;
function record() {
// Create empty array for saving trace values
2023-08-17 02:19:15 +00:00
T = new Array(K);
2023-01-31 20:06:27 +00:00
// Fill array with -1 so we can be sure memory is allocated
T.fill(-1, 0, T.length);
// Save start timestamp
start = performance.now();
2024-02-01 21:12:05 +00:00
// TODO (Exercise 3-1): Record data for 5 seconds and save values to T.
2023-01-31 20:06:27 +00:00
// 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);
}
};