Permalink
Browse files

cleaning demos

  • Loading branch information...
AlepH-FR committed Dec 10, 2010
1 parent 07a0a01 commit 50afe22abf30f01d2c296b9285b3e5c88ced1fa1
Showing with 29 additions and 153 deletions.
  1. +0 −6 README
  2. +3 −1 README.md
  3. +1 −1 demo.htm
  4. +14 −17 demos/pi/master.js
  5. +11 −9 demos/pi/worker.js
  6. +0 −23 demos/pi_bis/master.js
  7. +0 −53 demos/pi_bis/pibis_launcher.js
  8. +0 −26 demos/pi_bis/pibis_worker.js
  9. +0 −17 demos/pi_bis/worker.js
View
6 README
@@ -1,6 +0,0 @@
-Launch demo.htm to see how lemmings Workers are run.
-
-## To notice
-
-Actually, only the "pi" demo is running on the lemmings API, the 2 other demos are old demos here to tests the WebWorkers apis.
-They will be updated as soon as we would have a stable api for the lemmings workers
View
@@ -5,8 +5,10 @@ Launch demo.htm to see how lemmings Workers are run.
Actually, only the "pi" demo is running on the lemmings API, the 2 other demos are old demos here to tests the WebWorkers apis.
They will be updated as soon as we would have a stable api for the lemmings workers
-## TODO
+## To do
* test type of message to add a different behaviour in case of plain text messages
+
+ * rewrite and style the demo.htm page
* rewrite demos properly
* add another funky demo
View
@@ -29,6 +29,6 @@ <h2>Logs</h2>
<pre id="log"></pre>
<script type="text/javascript" src="src/lemmings/lemmings.js"></script>
- <script type="text/javascript" src="demos/pi_bis/master.js"></script>
+ <script type="text/javascript" src="demos/pi/master.js"></script>
</body>
</html>
View
@@ -1,26 +1,23 @@
-lemmings.url = 'http://lemmings.localhost';
-
var master = new lemmings.master();
-master.doOnMessage = function(data)
-{
- nb_workers_closed++;
- this.outputResult(4 * parseInt(data.value) / item_per_worker);
-
- total_data += parseInt(data.value);
- document.getElementById('global_result').textContent = (4 * total_data) / (nb_workers_closed * item_per_worker);
+master.onResultMessage = function(data)
+{
+ this.outputResult(data.dp);
+ total += parseFloat(data.dp);
+ document.getElementById('global_result').textContent = Math.sqrt(6 * total);
+
var now = new Date();
document.getElementById('elapsed').textContent = now.getTime() - master.date_start.getTime();
- result++;
+
+ this.log('worker closed');
+ this.terminate();
}
-var total_data = 0;
-var result = 0;
-var items_per_worker = 1000000;
-var nb_workers = 8;
-var nb_workers_closed = 0;
+var total = 0;
+var nb_workers = 4;
+var items_per_worker = 100000;
var data = [];
-for(var i = 0; i < nb_workers; i++) { data[i] = items_per_worker; }
-master.init('demos/pi/worker.js', data);
+for(var i = 0; i < nb_workers; i++) { data[i] = { start_value: i * items_per_worker }; }
+master.init('demos/pi_bis/worker.js', data);
master.run();
View
@@ -1,15 +1,17 @@
-
-this.process = function()
+this.onProcessMessage = function(data)
{
- var p = 0;
+ var n = 1 * data.start_value;
+ var end = n + 10000000;
- for(var i = 1 ; i <= parseInt(this.data) ; i++)
+ total = 0;
+ while (true)
{
- var x = Math.random();
- var y = Math.random();
- if((Math.pow(x, 2) + Math.pow(y, 2)) < 1) { p++; }
- }
+ n += 1;
+ if(n >= end) { break; }
- this.postJSONMessage({value: p});
+ total += 1 / Math.pow(n, 2);
+ }
+
+ this.postAction('Result', {dp: total});
this.close();
}
View
@@ -1,23 +0,0 @@
-var master = new lemmings.master();
-master.onResultMessage = function(data)
-{
- this.outputResult(data.dp);
-
- total += parseFloat(data.dp);
- document.getElementById('global_result').textContent = Math.sqrt(6 * total);
-
- var now = new Date();
- document.getElementById('elapsed').textContent = now.getTime() - master.date_start.getTime();
-
- this.log('worker closed');
- this.terminate();
-}
-
-var total = 0;
-var nb_workers = 4;
-var items_per_worker = 100000;
-
-var data = [];
-for(var i = 0; i < nb_workers; i++) { data[i] = { start_value: i * items_per_worker }; }
-master.init('demos/pi_bis/worker.js', data);
-master.run();
@@ -1,53 +0,0 @@
-// settings
-var num_workers = 4;
-var items_per_worker = 25000;
-
-// start the workers
-var result = 0;
-var pending_workers = num_workers;
-
-var timer_begin = new Date();
-for (var i = 0; i < num_workers; i += 1)
-{
- var output = document.createElement('output');
- output.id = 'output_' + i;
- document.getElementById('outputs').appendChild(output);
-
- var br = document.createElement('br');
- document.getElementById('outputs').appendChild(br);
-
- try
- {
- var worker = new Worker('pibis_worker.js');
- worker.postMessage("{id: " + i + ", start: " + (i * items_per_worker) + " }");
- worker.onmessage = storeResult;
- }
- catch(e)
- {
- alert('errr');
- log(e.message);
- }
- finally
- {
- log("worker no." + i + " launched");
- }
-}
-
-// handle the results
-total = 0;
-function storeResult(event)
-{
- var data = eval("(" + event.data + ")");
- document.getElementById('output_' + data.id).textContent = data.dp;
- total += parseFloat(data.dp);
- document.getElementById('nb_prime').textContent = total;
-
- var timer_end = new Date();
- document.getElementById('elapsed').textContent = timer_end.getTime() - timer_begin.getTime();
-
-}
-
-function log(t)
-{
- document.getElementById('log').textContent += t + "\n";
-}
@@ -1,26 +0,0 @@
-var id = null;
-
-onmessage = function work(event)
-{
- var data = eval("(" + event.data + ")");
- var n = 1 * data.start;
-
- total = 0;
- search: while (true)
- {
- n += 1;
- if(n >= data.start + 25000) { break search; }
-
- var r1 = 4 / ((8 * n) + 1 );
- var r2 = 2 / ((8 * n) + 4 );
- var r3 = 1 / ((8 * n) + 5 );
- var r4 = 1 / ((8 * n) + 6 );
- var r5 = Math.pow((1 / 16), n);
- var m = (r1 - r2 - r3 - r4) * r5;
- total += m;
-
- postMessage("{id: " + data.id + ", dp: " + total + "}");
- }
-
- close();
-}
View
@@ -1,17 +0,0 @@
-this.onProcessMessage = function(data)
-{
- var n = 1 * data.start_value;
- var end = n + 10000000;
-
- total = 0;
- while (true)
- {
- n += 1;
- if(n >= end) { break; }
-
- total += 1 / Math.pow(n, 2);
- }
-
- this.postAction('Result', {dp: total});
- this.close();
-}

0 comments on commit 50afe22

Please sign in to comment.