Merge remote-tracking branch 'origin/main_desktop_1' into sub_laptop_8
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/* =============================================================================
|
||||
* test_stage4_menu_perf.ts — 우클릭 속도(81-2③) 재현 시험. 돌리기: npx tsx <이 파일>.
|
||||
* `spreadsheet_menu.ts` rowMenuItems/colMenuItems 의 `at` 계산 — 옛 Math.min(...rows) 는
|
||||
* 전체 고름(열 머리 104만 개) 배열을 스프레드해 콜스택을 넘침(RangeError) · 고친 `rows[0]`
|
||||
* (rows 는 늘 오름차순 연속이라 첫 자리가 최소)는 크기와 무관하게 안전·상수 시간.
|
||||
* `computeSelectionStats` 쪽(①)은 createMapContextMenu 가 끌어오는 css 임포트 때문에
|
||||
* 이 node 시험 환경에서 직접 불러오지 못함 — ORCA 화면 검증으로 수치 확인(81-2 보고 참고).
|
||||
* ========================================================================== */
|
||||
|
||||
import { MAX_COLS, MAX_ROWS } from "../../../A00_Common/spreadsheet/spreadsheet_types.ts";
|
||||
import { assertEqual } from "./test_stage2_helpers.ts";
|
||||
|
||||
const bigRows = Array.from({ length: MAX_ROWS }, (_, i) => i); // 열 머리 전체 고름 재현
|
||||
|
||||
let oldThrew = false;
|
||||
try {
|
||||
Math.min(...bigRows); // 옛 코드 — 이 크기에선 RangeError(콜스택 넘침)
|
||||
} catch {
|
||||
oldThrew = true;
|
||||
}
|
||||
if (!oldThrew) {
|
||||
console.error(
|
||||
"FAIL 옛 Math.min(...rows) 재현 실패 — 이 Node 가 다른 콜스택 한도를 씀(시험 전제 깨짐)",
|
||||
);
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
console.log("ok 옛 Math.min(...rows) 는 104만 개에서 콜스택을 넘침(고치기 전 재현)");
|
||||
}
|
||||
|
||||
const t0 = performance.now();
|
||||
const at = bigRows[0]; // 고친 코드(spreadsheet_menu.ts rowMenuItems)
|
||||
const ms = performance.now() - t0;
|
||||
assertEqual(at, 0, "rows[0] = 최소값(오름차순 연속)");
|
||||
if (ms >= 5) {
|
||||
console.error(`FAIL rows[0] 은 5ms 안(상수 시간) — 실측 ${ms.toFixed(2)}ms`);
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
console.log(`ok rows[0] ${ms.toFixed(3)}ms(크기 무관 상수 시간)`);
|
||||
}
|
||||
|
||||
// 열 머리(MAX_COLS) 도 같은 모양
|
||||
const bigCols = Array.from({ length: MAX_COLS }, (_, i) => i);
|
||||
assertEqual(bigCols[0], 0, "cols[0] = 최소값");
|
||||
|
||||
if (process.exitCode) process.exit(process.exitCode);
|
||||
console.log("spreadsheet_menu 우클릭 속도(81-2③) 시험 끝");
|
||||
Reference in New Issue
Block a user