-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThread.html
55 lines (52 loc) · 1.86 KB
/
Thread.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
<!DOCTYPE html>
<html>
<body>
<div id="info">Press start to run 1,000,000,000 sized two loops in parrallel.</div>
<div><button id = "start">Start</button></div>
<div id="loop1"></div>
<div id="loop2"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="thread.js"></script>
<script>
$(document).ready(function () {
$('#start').on('click', function () {
executeCode();
});
});
var executeCode = function () {
$("#info").html("Loops are running .... wait for few seconds !");
var monitorStart = new Date();
var count = 1000000000;
/* First thread */
var thread1 = new Thread();
thread1.start(count, function (size) {
var x = 0;
for (var i = 1; i < size; i++) {
x = x + i;
}
return x;
}).then(function (result) {
var monitorEnd = new Date();
$("#loop1").html("Time taken for thread 1: " + (monitorEnd - monitorStart) + " milliseconds");
this.close();
}).fail(function (error) {
console.log(error);
});
var thread2 = new Thread();
thread2.start(count, function (size) {
var x = 0;
for (var i = 1; i < size; i++) {
x = x + i;
}
return x;
}).then(function (result) {
var monitorEnd = new Date();
$("#loop2").html("Time taken for thread 2: " + (monitorEnd - monitorStart) + " milliseconds");
this.close();
}).fail(function (error) {
console.log(error);
});
}
</script>
</body>
</html>