December 07, 2005
AFAIK,
this should be similar to DMD's new -cov flag:
(http://www.digitalmars.com/d/code_coverage.html)

# gdc -o sieve -fprofile-arcs -ftest-coverage sieve.d
# ./sieve
10 iterations

1899 primes
# gcov sieve.d                               100.00% of 15 lines executed in file sieve.d
Creating sieve.d.gcov.

The contents of "sieve.d.gcov" is similar to "sieve.lst",
though it is using different separators and number display:

        -:    0:Source:sieve.d
        -:    0:Object:sieve.bb
        -:    1:/* Sieve of Eratosthenes prime numbers */
        -:    2:bit[8191] flags;
        -:    3:
        2:    4:void main()
        -:    5:{
        1:    6:  int i, count, prime, k;
        1:    7:  printf("10 iterations\n");
        1:    8:  for (int iter = 1; iter <= 10; iter++)
        -:    9:  {
       10:   10:    count = 0;
       10:   11:    flags[] = 1;
       10:   12:    for (i = 0; i < flags.length; i++)
        -:   13:    {
    81910:   14:      if (flags[i])
        -:   15:      {
    18990:   16:        prime = i + i + 3;
    18990:   17:        k = i + prime;
   168980:   18:        while (k < flags.length)
        -:   19:        {
   149990:   20:          flags[k] = 0;
   149990:   21:          k += prime;
        -:   22:        }
    18990:   23:        count += 1;
        -:   24:      }
        -:   25:    }
        -:   26:  }
        1:   27:  printf ("\n%d primes\n", count);
        -:   28:}

It seems to start the count of loops (etc) diffently,
but I'm not sure what significance that will have...

HTH,
--anders
December 08, 2005
Anders F Björklund wrote:
> AFAIK,
> this should be similar to DMD's new -cov flag:
> (http://www.digitalmars.com/d/code_coverage.html)
> 
> # gdc -o sieve -fprofile-arcs -ftest-coverage sieve.d
> # ./sieve
> 10 iterations
> 
> 1899 primes
> # gcov sieve.d                               100.00% of 15 lines executed in file sieve.d
> Creating sieve.d.gcov.
> 
> The contents of "sieve.d.gcov" is similar to "sieve.lst",
> though it is using different separators and number display:
> 
<snip>
> 
> It seems to start the count of loops (etc) diffently,
> but I'm not sure what significance that will have...
> 
> HTH,
> --anders

There are some improvements to line numbering that can be made.  I tried out the equivalent C code and it is closer to the DMD output.

David