SHD-WebsiteFingerprintingLab/part1/warmup.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-01-31 20:06:27 +00:00
const runs = 10;
2024-11-02 12:50:02 +00:00
const N= 393216;
2023-01-31 20:06:27 +00:00
function measureOneLine() {
2024-11-02 12:50:02 +00:00
const LINE_SIZE = 8; // 64/sizeof(double) Note that js treats all numbers as double
2023-01-31 20:06:27 +00:00
let result = [];
// Fill with -1 to ensure allocation
const M = new Array(runs * LINE_SIZE).fill(-1);
for (let i = 0; i < runs; i++) {
const start = performance.now();
let val = M[i * LINE_SIZE];
const end = performance.now();
2024-11-02 12:50:02 +00:00
result.push((end - start).toFixed(2));
2023-01-31 20:06:27 +00:00
}
return result;
}
function measureNLines() {
2024-11-02 12:50:02 +00:00
const LINE_SIZE = 8; // 64/sizeof(double) Note that js treats all numbers as double
2023-01-31 20:06:27 +00:00
let result = [];
2024-11-02 12:50:02 +00:00
// Fill with -1 to ensure allocation
const M = new Array(runs * N * LINE_SIZE).fill(-1);
for (let i = 0; i < runs; i++) {
const start = performance.now();
for (let j = 0; j < N; j++) {
let val = M[i * N * LINE_SIZE + j * LINE_SIZE];
}
const end = performance.now();
result.push((end - start).toFixed(2));
}
2023-01-31 20:06:27 +00:00
return result;
}
document.getElementById(
"exercise1-values"
).innerText = `1 Cache Line: [${measureOneLine().join(", ")}]`;
document.getElementById(
"exercise2-values"
).innerText = `N Cache Lines: [${measureNLines().join(", ")}]`;