2023-01-31 20:06:27 +00:00
|
|
|
const runs = 10;
|
|
|
|
|
|
|
|
function measureOneLine() {
|
2024-02-01 21:12:05 +00:00
|
|
|
const LINE_SIZE = 32; // 128/sizeof(int)
|
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();
|
|
|
|
|
|
|
|
result.push(end - start);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function measureNLines() {
|
|
|
|
let result = [];
|
|
|
|
|
2023-02-06 17:43:32 +00:00
|
|
|
// TODO: Exercise 1-1
|
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(", ")}]`;
|