I tested three different algorithms to find prime number between 1 - n.
Note: Tested in Bun v1.1.13 runtime.
The results are surprising because Dijkstra's Approach is expected to be faster than Trial Division but slower than Sieve of Eratosthenes. My theory is that since JavaScript does not have a native heap implementation, this makes Dijkstra's Approach slower.
Please feel free to open Issues or PRs if you find any problems or you can improve the implementation.
- Trial Division (Wikipedia page)
- Sieve of Eratosthenes (Wikipedia page)
- Dijkstra's Prime Algorithm (Webpage)
- Dijkstra's Hidden Prime Finding Algorithm (YouTube Video)