Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I put together (based on your code) two more comparable tests in C and C#. These two write a smaller array using the modulus operator for indexing (it adds a little overhead, but hey, we're trying to compare performance [at a crude level]).</p> <p>C code:</p> <pre><code>#include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;time.h&gt; #include &lt;math.h&gt; void main() { int count = (int)1e8; int subcount = 1000; double* roots = (double*)malloc(sizeof(double) * subcount); clock_t start = clock(); for (int i = 0 ; i &lt; count; i++) { roots[i % subcount] = sqrt((double)i); } clock_t end = clock(); double length = ((double)end - start) / CLOCKS_PER_SEC; printf("Time elapsed: %f\n", length); } </code></pre> <p>In C#:</p> <pre><code>using System; namespace CsPerfTest { class Program { static void Main(string[] args) { int count = (int)1e8; int subcount = 1000; double[] roots = new double[subcount]; DateTime startTime = DateTime.Now; for (int i = 0; i &lt; count; i++) { roots[i % subcount] = Math.Sqrt(i); } TimeSpan runTime = DateTime.Now - startTime; Console.WriteLine("Time elapsed: " + Convert.ToString(runTime.TotalMilliseconds / 1000)); } } } </code></pre> <p>These tests write data to an array (so the .NET runtime shouldn't be allowed to cull the sqrt op) although the array is significantly smaller (didn't want to use excessive memory). I compiled these in release config and run them from inside a console window (instead of starting through VS).</p> <p>On my computer the C# program varies between 6.2 and 6.9 seconds, while the C version varies between 6.9 and 7.1.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload