-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
126 lines (124 loc) · 3.99 KB
/
index.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Merge Sort</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
font-family: 'Courier New', Courier, monospace;
padding: 10px;
}
.heading {
text-align: center;
}
.container {
display: flex;
flex-direction: row;
height: 40vh;
border: 1px solid black;
}
.container > div {
border: 1px solid black;
flex: 1;
padding: 10px;
}
.topic {
text-align: center;
}
.btn {
padding: 5px 10px;
background-color: blue;
color: white;
outline: none;
justify-self: center;
align-self: center;
width: 100px;
transition: all 300ms;
}
.btn:hover {
background-color: rgb(10, 10, 193);
cursor: pointer;
}
.btn:active {
outline: none;
}
.btn:disabled {
background-color: gray;
}
.left,
.right {
display: flex;
flex-direction: column;
}
</style>
<script src="./merge-sort.js"></script>
</head>
<body>
<h2 class="heading">Distributed merge sort</h2>
<div class="container">
<div class="left">
<p class="topic">Normal Merge Sort</p>
<button class="btn" id="norm-sorting-btn">Start sorting</button>
<div>Status: <span id="norm-status">Not running</span></div>
<div id="norm-stats">
<b>Stats : </b><br />
Array Size -> <span id="n-array-size"></span> <br />
Start Time -> <span id="n-start-time"></span> <br />
End Time -> <span id="n-end-time"></span> <br />
Total Time -> <span id="n-total-time"></span>
</div>
</div>
<div class="right">
<p class="topic">Distributed Merge Sort</p>
<button class="btn" id="dist-sorting-btn">Start sorting</button>
<div>Status: <span id="dist-status">Not running</span></div>
<div id="dist-stats">
<b>Stats : </b><br />
Array Size -> <span id="d-array-size"></span> <br />
Start Time -> <span id="d-start-time"></span> <br />
End Time -> <span id="d-end-time"></span> <br />
Total Time -> <span id="d-total-time"></span>
</div>
</div>
</div>
<div style="margin:10px">
Comparision of a Normal Merge Sort and Distributed Merge Sort is used.
<br /><br />
<b>Normal Merge Sort</b>: It is done in the main thread (the only thread)
, basic implementaion of merge sort. <br /><br />
<b>Distributed Merge Sort</b>: It is done in the worker threads, by using
at max 4 worker threads at a time. Merge Sorting 1/4 of part array in
different workers. Then merging the 4 parts, in two different workers by
making it parallel. Thereby speeding it up.
<br />
Using
<a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer"
>SharedArrayBuffer</a
>, we can easily send reference to the worker threads without the overhead
of copying over. Combining
<a
href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers"
>Web Workers</a
>
and
<a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer"
>SharedArrayBuffer</a
>,We can implement a lot of parallel algorithms, achieve speed which was
possible in low level languages. Also read,
<a
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays"
>TypedArrays</a
>
which makes numerical arrays creation superfast.
</div>
<script src="./index.js"></script>
</body>
</html>