-
Notifications
You must be signed in to change notification settings - Fork 0
/
jspmap.html
executable file
·118 lines (104 loc) · 4.33 KB
/
jspmap.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
<!doctype html>
<html>
<head>
<title>So I heard you liek parallelism</title>
</head>
<script src="jspmap.js"></script>
<body>
<div id="status"></div>
<strong>Regular map</strong>
<div id="result1"></div>
<div id="time1"></div>
<strong>Parallel map</strong>
<div id="result2"></div>
<div id="time2"></div>
<strong>Parallel workers</strong>
<div id="result3"></div>
<div id="time3"></div>
<script>
var testblob = function(callback, failback) {
var boo = setTimeout(failback, 1000);
try{
var bb = new BlobBuilder();
bb.append("self.onmessage = function(event) { self.postMessage('hello thar'); }");
var enc = window.URL.createObjectURL(bb.getBlob());
var w = new Worker(enc);
w.onmessage = function () {
clearTimeout(boo);
callback();
}
w.postMessage("hey");
}
catch (e) {
clearTimeout(boo);
failback(e);
}
}
var dotest = function() {
var fun = function(x) {
var q = 3;
for(i = 0; i < x*300000; i++) {
q *= 3.1;
q = q % 10000000;
}
return q;
}
var list = [];
var start;
var diff;
for(var i = 0; i < 50; i++) {
list.push(i);
}
map(fun, list);
document.getElementById("status").innerHTML = "Running for real now...";
var trial2 = function() {
start = (new Date).getTime();
parallelmap(fun, list,
function(result2) {
var diff = (new Date).getTime() - start;
document.getElementById("time2" ).innerHTML = diff+" msec";
document.getElementById("result2").innerHTML = result2.toString();
setTimeout(trial3, 500);
});
}
var trial1 = function() {
start = (new Date).getTime();
var result1 = map(fun, list);
diff = (new Date).getTime() - start;
document.getElementById("result1").innerHTML = result1.toString();
document.getElementById("time1" ).innerHTML = diff+" msec";
setTimeout(trial2, 500);
}
var trial3 = function() {
document.getElementById("time3" ).innerHTML = "starting...";
start = (new Date).getTime();
parallelworkers("modulo.js", list,
function(result3) {
var diff = (new Date).getTime() - start;
document.getElementById("time3" ).innerHTML = diff+" msec";
document.getElementById("result3").innerHTML = result3.toString();
});
}
setTimeout(trial1, 500);
}
testblob(function() {
document.getElementById("status").innerHTML = "Wasting cycles...";
setTimeout(dotest, 100);
}, function(e) {
document.getElementById("status").innerHTML =
"This isn't going to work on your browser: <tt>"+e+"</tt>";
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-870770-7']);
_gaq.push(['_setDomainName', '.ericjiang.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>