]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Implemented more precise calculation in negobench
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 29 Jul 2009 15:35:03 +0000 (17:35 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 29 Jul 2009 15:35:03 +0000 (17:35 +0200)
The previous version used float arithmetics which caused the results to
be incorrect because of rounding errors -- especially on fast computers.
This version uses exact time calculations.

frsh_api/tests/negobench.c

index 87a8f156d01f9e9b259e19461fdbc2b2e0538897..36d990b525c61120d8b7ceff48dc17b30c0393b7 100644 (file)
@@ -59,7 +59,10 @@ int main(int argc, char *argv[])
                ret = frsh_contract_negotiate(&contract[i], &vres[i]);
                if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
                clock_gettime(CLOCK_MONOTONIC, &t_end);
-               printf("%d %g\n", i, (float)(t_end.tv_sec+1e-9*t_end.tv_nsec) - (t_start.tv_sec+1e-9*t_start.tv_nsec));
+               uint64_t ns;
+               ns = (uint64_t)(t_end.tv_sec - t_start.tv_sec)*1000000000;
+               ns += t_end.tv_nsec - t_start.tv_nsec;
+               printf("%d %d.%09d\n", i, (int)(ns/1000000000), (int)(ns%1000000000));
        }
        /* Cancel N contracts */
        for (i=0; i<n; i++) {