Prime: Difference between revisions

From Freephile Wiki
Created page with "== Prime Real Estate == This demo page http://www.whatwg.org/demos/workers/primes/page.html from the Web Hypertext Application Technology Working Group shows prime numbers. W..."
 
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight"
 
(3 intermediate revisions by 3 users not shown)
Line 2: Line 2:
This demo page
This demo page
http://www.whatwg.org/demos/workers/primes/page.html
http://www.whatwg.org/demos/workers/primes/page.html
from the Web Hypertext Application Technology Working Group shows prime numbers.  What I found interesting is that initially, it takes a few moments to find prime numbers; meaning that they are "far apart" as you examine every number up to say 1,000,000.  But suddenly the demo application is spitting out prime numbers faster than you can read.  So, apparently there are a lot of prime numbers once you get into the larger numbers.  But this isn't actually true.  If you look at the distribution of primes, there are "more" smaller primes than larger primes.  Hmm.
from the Web Hypertext Application Technology Working Group shows prime numbers.  What I found interesting is that initially, it takes a few moments to find prime numbers; meaning that they are "far apart" as you examine every number up to say 1,000,000.  But suddenly the demo application is spitting out prime numbers faster than you can read.  So, apparently there are a lot of prime numbers once you get into the larger numbers.  But this isn't actually true.  If you [http://yoyo.cc.monash.edu.au/~bunyip/primes/ look at the distribution of primes], there are "more" smaller primes than larger primes (X < 200) <ref>http://primes.utm.edu/howmany.shtml</ref>.  Hmm.


<source lang="html5">
<syntaxhighlight lang="html5">
<!DOCTYPE HTML>
<!DOCTYPE HTML>
<html>
<html>
Line 20: Line 20:
  </body>
  </body>
</html>
</html>
</source>
</syntaxhighlight>


== Concurrency ==
== Concurrency ==
Line 27: Line 27:
With "workers" you can perform a computationally expensive task without interrupting the user interface.
With "workers" you can perform a computationally expensive task without interrupting the user interface.


In this example, the main document spawns a worker to () compute prime numbers, and progressively displays the most recently found prime number.
In this example, the main document spawns a worker to (naively) compute prime numbers, and progressively displays the most recently found prime number.
 
== Word of the Day ==
pul-chri-tu-di-nous; adj. Very pleasing or delightful to look at - Characterized by, or having great physical beauty and appeal.
 
{{References}}


[[Category:JavaScript]]
[[Category:JavaScript]]

Latest revision as of 13:30, 24 February 2025

Prime Real Estate[edit]

This demo page http://www.whatwg.org/demos/workers/primes/page.html from the Web Hypertext Application Technology Working Group shows prime numbers. What I found interesting is that initially, it takes a few moments to find prime numbers; meaning that they are "far apart" as you examine every number up to say 1,000,000. But suddenly the demo application is spitting out prime numbers faster than you can read. So, apparently there are a lot of prime numbers once you get into the larger numbers. But this isn't actually true. If you look at the distribution of primes, there are "more" smaller primes than larger primes (X < 200) [1]. Hmm.

<!DOCTYPE HTML>
<html>
 <head>
  <title>Worker example: One-core computation</title>
 </head>
 <body>
  <p>The highest prime number discovered so far is: <output id="result"></output></p>
  <script>
   var worker = new Worker('worker.js');
   worker.onmessage = function (event) {
     document.getElementById('result').textContent = event.data;
   };
  </script>
 </body>
</html>

Concurrency[edit]

Aside from that, this demo illustrates how HTML5 brings multi-threaded execution or concurrency to your web application.

With "workers" you can perform a computationally expensive task without interrupting the user interface.

In this example, the main document spawns a worker to (naively) compute prime numbers, and progressively displays the most recently found prime number.

Word of the Day[edit]

pul-chri-tu-di-nous; adj. Very pleasing or delightful to look at - Characterized by, or having great physical beauty and appeal.

References[edit]