Matus Chochlik wrote
On Tue, Jun 10, 2014 at 8:58 AM, Vladimir Batov <
vb.mail.247@
> wrote:
IMHO this could have something to do with paging or the caching of the strings. You should test the two cases by two separate programs and try to run them both in the raw then cnv and cnv then raw orders. Or you could at least try to run
for (int k = 0; k < 3; ++k) printf("str-to-int spirit: raw1/raw2=%.2f/%.2f seconds.\n", performance_string_to_int_spirit(strings), performance_string_to_int_spirit(strings));
to try it out.
Matus,
Geez, I would never figure that out by myself. Thanks. So, the first call would pull the strings into the fast cache so that the second call would not have to, right? Now I changed the test as
int const num_tries = 20; double raw_time = 0; double cnv_time = 0;
Vladimir,
if this is indeed caused by caching and you want to run both tests in a single program, then you should do a "dry run" that will cause the strings to be cached before you do the actual timing. Also I'd increase the number of tries at least to 200.
for (int k = 0; k < num_tries; ++k) raw_time += performance_string_to_int_spirit(strings);
for (int k = 0; k < num_tries; ++k) cnv_time += performance::str_to_int(strings, boost::cnv::spirit());
printf("str-to-int spirit: raw/cnv=%.2f/%.2f seconds.\n", raw_time / num_tries, cnv_time / num_tries);
Does it look fair to you? It surely gives more realistic results with bosst::convert() adding 0.7% overhead:
32:~/dev/boost.convert.>> ~/dev/bin/test-convert str-to-int spirit: raw/cnv=1.41/1.42 seconds.
Well, it seems I spoke too soon. I was rushing out and tried the above in a hurry and, as a result, messed it up. Now I am doubtful it's cache-related as I simply run for (int k = 0; k < num_tries; ++k) { double raw_time1 = performance_string_to_int_spirit(strings); double raw_time2 = performance_string_to_int_spirit(strings); printf("str-to-int spirit: raw1/raw2=%.2f/%.2f seconds.\n", raw_time1, raw_time2); } and both raw_time1 and raw_time2 are the same (well, there is some variation but really minor and random). Then I run for (int k = 0; k < num_tries; ++k) { double cnv_time = performance::str_to_int(strings, boost::cnv::spirit()); double raw_time = performance_string_to_int_spirit(strings); printf("str-to-int spirit: raw/cnv=%.2f/%.2f seconds (%.2f%%).\n", raw_time, cnv_time, 100 * cnv_time / raw_time); } and regardless if I calculate cnv_time first or raw_time first I get the same results (i.e. the first call does not help the second call at all) as below: str-to-int spirit: raw/cnv=1.46/1.42 seconds (97.34%). str-to-int spirit: raw/cnv=1.47/1.42 seconds (96.15%). str-to-int spirit: raw/cnv=1.46/1.42 seconds (97.31%). str-to-int spirit: raw/cnv=1.45/1.42 seconds (97.45%). str-to-int spirit: raw/cnv=1.45/1.41 seconds (97.30%). I give up. My brain is too puny to understand that. -- View this message in context: http://boost.2283326.n4.nabble.com/review-Convert-library-tp4662821p4663936.... Sent from the Boost - Dev mailing list archive at Nabble.com.