-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-30k.html
More file actions
106 lines (96 loc) · 4.23 KB
/
Copy pathtest-30k.html
File metadata and controls
106 lines (96 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>V1.5 - 30000条测试</title>
<style>
body { font-family: Arial; padding: 20px; background: #f5f5f5; }
.container { max-width: 1000px; margin: 0 auto; background: white; padding: 30px; }
button { padding: 12px 24px; background: #3498db; color: white; border: none; border-radius: 5px; cursor: pointer; margin: 10px 5px; }
button:disabled { background: #999; }
.progress { width: 100%; height: 30px; background: #ddd; border-radius: 5px; margin: 10px 0; }
.progress-bar { height: 100%; background: #3498db; transition: width 0.3s; text-align: center; line-height: 30px; color: white; }
.result { margin: 10px 0; padding: 15px; background: #ecf0f1; border-left: 4px solid #3498db; }
.success { border-left-color: #2ecc71; }
</style>
</head>
<body>
<div class="container">
<h1> V1.5 性能测试 - 30000 条文献</h1>
<h3>步骤 1: 生成测试数据</h3>
<button id="btnGen" onclick="generate()">生成 30000 条数据</button>
<div class="progress" id="prog1" style="display:none">
<div class="progress-bar" id="bar1">0%</div>
</div>
<div id="res1"></div>
<h3>步骤 2: 导入 IndexedDB</h3>
<button id="btnImport" onclick="importData()" disabled>导入数据库</button>
<div class="progress" id="prog2" style="display:none">
<div class="progress-bar" id="bar2">0%</div>
</div>
<div id="res2"></div>
<h3>步骤 3: 查询测试</h3>
<button id="btnQuery" onclick="queryTest()" disabled>查询100条</button>
<div id="res3"></div>
</div>
<script src="virtual-list.js"></script>
<script>
let data = [];
let dbWorker = new Worker("db-worker.js");
dbWorker.onmessage = (e) => {
console.log("Worker:", e.data);
if (e.data.type === "IMPORT_PROGRESS") {
let p = Math.floor((e.data.inserted / e.data.total) * 100);
document.getElementById("bar2").style.width = p + "%";
document.getElementById("bar2").textContent = p + "%";
} else if (e.data.type === "IMPORT_COMPLETE") {
document.getElementById("prog2").style.display = "none";
document.getElementById("res2").innerHTML = "<div class=result success> 导入完成: " + e.data.result.imported + " 条</div>";
document.getElementById("btnQuery").disabled = false;
}
};
function generate() {
document.getElementById("btnGen").disabled = true;
document.getElementById("prog1").style.display = "block";
data = [];
let start = Date.now();
for (let i = 0; i < 30000; i++) {
data.push({
title: "Study " + i + ": " + ["Cancer", "Diabetes", "Heart"][i % 3],
authors: "Author" + i,
year: 2000 + (i % 25),
doi: "10.1000/" + i
});
if (i % 1000 === 0) {
let p = Math.floor((i / 30000) * 100);
document.getElementById("bar1").style.width = p + "%";
document.getElementById("bar1").textContent = p + "%";
}
}
let time = ((Date.now() - start) / 1000).toFixed(2);
document.getElementById("prog1").style.display = "none";
document.getElementById("res1").innerHTML = "<div class=result success> 生成完成: 30000 条,耗时 " + time + "s</div>";
document.getElementById("btnGen").disabled = false;
document.getElementById("btnImport").disabled = false;
}
function importData() {
document.getElementById("btnImport").disabled = true;
document.getElementById("prog2").style.display = "block";
dbWorker.postMessage({ type: "CLEAR_DATA" });
setTimeout(() => {
dbWorker.postMessage({ type: "IMPORT_RECORDS", data: { records: data, batchSize: 500 }});
}, 100);
}
function queryTest() {
let start = Date.now();
dbWorker.postMessage({ type: "GET_PAGED", data: { pageNum: 0, pageSize: 100 }});
dbWorker.onmessage = (e) => {
if (e.data.type === "PAGED_RESULT") {
let time = Date.now() - start;
document.getElementById("res3").innerHTML = "<div class=result success> 查询完成: 返回 " + e.data.paged.records.length + " 条,耗时 " + time + "ms</div>";
}
};
}
</script>
</body>
</html>