10001th prime: Difference between revisions
Content added Content deleted
m (→{{header|C#|CSharp}}: not sure why "@ Tio.run" was removed, added "trial division" mention.) |
|||
Line 201: | Line 201: | ||
=={{header|C#|CSharp}}== |
=={{header|C#|CSharp}}== |
||
Comparing performance of the one-at-a-time method vs the sieve of Eratosthenes method. About ten times faster for the sieve. It may appear that the sieve may be off by one, <code>pr[10000]</code> but since the array is zero based, it's the 10001st value. |
Comparing performance of the one-at-a-time trial division method vs the sieve of Eratosthenes method. About ten times faster for the sieve. It may appear that the sieve may be off by one, <code>pr[10000]</code> but since the array is zero based, it's the 10001st value. |
||
<lang csharp>using System; class Program { |
<lang csharp>using System; class Program { |
||
Line 214: | Line 214: | ||
static void Main(string[] args) { |
static void Main(string[] args) { |
||
Console.WriteLine("One-at-a-time vs sieve of Eratosthenes"); |
Console.WriteLine("One-at-a-time trial division vs sieve of Eratosthenes"); |
||
var sw = System.Diagnostics.Stopwatch.StartNew(); |
var sw = System.Diagnostics.Stopwatch.StartNew(); |
||
var t = prime(10001); sw.Stop(); double e1, e2; |
var t = prime(10001); sw.Stop(); double e1, e2; |
||
Line 230: | Line 230: | ||
Console.Write(" {0:n0} {1} μs {2:0.000} times faster", t, |
Console.Write(" {0:n0} {1} μs {2:0.000} times faster", t, |
||
(e2 = sw.Elapsed.TotalMilliseconds) * 1000.0, e1 / e2); } }</lang> |
(e2 = sw.Elapsed.TotalMilliseconds) * 1000.0, e1 / e2); } }</lang> |
||
{{out|Output}} |
{{out|Output @ Tio.run}} |
||
<pre>One-at-a-time vs sieve of Eratosthenes |
<pre>One-at-a-time trial division vs sieve of Eratosthenes |
||
104,743 3.8943 ms 104,743 357.9 μs 10.881 times faster</pre> |
104,743 3.8943 ms 104,743 357.9 μs 10.881 times faster</pre> |
||
=={{header|C#|CSharp}}== |
=={{header|C#|CSharp}}== |