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();
|
|
|
|
|
2023-02-06 17:45:10 +00:00
|
|
|
// TODO (Exercise 3-1): Record data for TRACE_LENGTH 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") {
|
|
|
|
TRACE_LENGTH = e.data.trace_length;
|
|
|
|
setTimeout(record, 0);
|
|
|
|
}
|
|
|
|
};
|