Also, when measuring performance difference for small cycles loops like
these, the cost of the framework code should not be discounted.
In theory you should have a testovf() that simply returns 1 (or 0), run the
test with it, and subtract that time from every test.
This will give the more exact measure of the relative savings.


On Tue, Dec 1, 2015 at 3:17 PM, Davide Libenzi <[email protected]> wrote:

> On Tue, Dec 1, 2015 at 3:05 PM, barret rhoden <[email protected]>
> wrote:
>
>> > size_t qrand(void)
>> > {
>> >     return ((size_t) rand() << 4) ^ rand();
>>
>> Was this to make it possible to get rands > (1 << 32) (and thus capable
>> of overflow)?
>>
>
> Just to make the CPU running in a tight loop like that, to cache the hint
> and run for it for the whole lifetime of the test.
>
>
> >     printf("c = %zd\n", c);
>>
>> What value of c did you get?
>>
>
>
> I already change the code to use something like this for main_test.c
> (result did not change much WRT the previous):
>
> #include <stddef.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> extern int testovf(size_t a, size_t b);
> extern size_t base(void);
>
> size_t num_values = 100000;
>
> size_t qrand(void)
> {
>     size_t v = rand();
>
>     if (rand() & 16)
>         v += (1UL << (sizeof(size_t) * 4));
>
>     return v;
> }
>
> int main(void)
> {
>     size_t i, j, c;
>     size_t *vals = calloc(num_values, sizeof(size_t));
>
>     for (c = 0; c < num_values; c++) {
>         do {
>             vals[c] = qrand();
>         } while (!vals[c]);
>     }
>     c = 0;
>     for (i = 0; i < 4000; i++) {
>         for (j = base(); j < num_values; j++) {
>             c += testovf(vals[j - 1], vals[j]);
>         }
>     }
>     printf("c = %zd\n", c);
>
>     return 0;
> }
>
>
>
> dlibenzi@dlibenzi:/tmp$ time ./test_div
> c = 100396000
>
> real 0m3.368s
> user 0m3.360s
> sys 0m0.004s
>
>
> dlibenzi@dlibenzi:/tmp$ time ./test_obsd
> c = 100396000
>
> real 0m3.752s
> user 0m3.748s
> sys 0m0.000s
>
>
> dlibenzi@dlibenzi:/tmp$ time ./test_int128
> c = 100396000
>
> real 0m0.564s
> user 0m0.563s
> sys 0m0.000s
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Akaros" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to