33 lines
860 B
JavaScript
33 lines
860 B
JavaScript
// 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 4-4): Copy your solution from part 3. Optionally make changes to your part 3 solution if you need to.
|
|
|
|
// 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);
|
|
}
|
|
};
|