Counting Primes

3-1: A Speed Comparison

Alright. Want to see how far we've come?

Sure.

Now, keep in mind, this is a really pretty rough test here. I'll spawn each algorithm off in its own worker thread in the web browser.

What is the consequence of that?

Well, depending on your machine, you might or might not have different physical CPUs to run each of those threads. So the timings should be taken with a grain of salt. Nevertheless, this framework should be enough to give a good general sense of the progress of the algorithms we worked through here.

Try running these to satisfy your curiosity, and then I have a few more things to point out.

Okay, at least on my machine, running those generally seemed to confirm what we already worked through, which is good.

Keep in mind, if you click the algorithm names, you'll open the JavaScript files that I'm actively running in the browser, so you can see what code is actually being run live.

Ah, that's helpful.

So these are useful comparisons, or I hope they are. But they're not the only possible way to count primes. I'm finally ready to answer what I said would be a surprisingly complicated question - how this broad approach compares to other approaches. Would you like to see how this compares?

Sure.

Great. In a moment, I will have another table running some of these algorithms live against some completing approaches to counting primes. But before I do, let me take a step back and do a quick survey of algorithms...