-
Notifications
You must be signed in to change notification settings - Fork 0
/
cw6.html
78 lines (55 loc) · 2.03 KB
/
cw6.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Compare Array and Map</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="https://www.w3schools.com/w3css/4/w3.css" />
<script src="HW2/Database.js"></script>
</head>
<body>
<form>
Comparing between ARRAY and MAP:
<br>
<input type="button" onclick="show()" value="Compare">
</form>
<p id="myData"></p>
</body>
<script>
function show() {
let p = document.getElementById("myData");
// p.innerText = "test " + Math.floor(Math.random() * 1000000000);
let randmoNumber;
let counterMap = 0;
let counterArr = 0;
// p.innerText = "random Student = " + randmoNumber;
let keys = Array.from(db.stumap.keys());
let max = 716363208
let min = 116690070
let arrPerf = 0;
let mapPerf = 0;
let t = performance.now()
for (let index = 0; index < 10000; index++) {
// randmoNumber = Math.random() * (max - min) + min;
randmoNumber = "116690" + String(Math.random()).substring(2, 5);
t = performance.now()
if (keys.includes(String(randmoNumber)))
counterArr++
arrPerf += performance.now() - t
t = performance.now()
if (db.stumap.has(String(randmoNumber))) {
counterMap++
}
mapPerf += performance.now() - t
}
p.innerText += "\n array performance(msc)=" + arrPerf.toPrecision(3) +
"\n map performance(msc)=" + mapPerf.toPrecision(3) +
"\nMap found " + counterMap +
"\nArray found " + counterArr +
"\nRatio:(map/array)" +
(arrPerf.toPrecision(3) / mapPerf.toPrecision(3))
+"\n";
};
</script>
</html>