patch: basic_string.tcc
Dhruv Matani
dhruvbird@gmx.net
Tue Jul 20 10:35:00 GMT 2004
Oops, forgot the file!
On Tue, 2004-07-20 at 16:17, Dhruv Matani wrote:
> Hi,
> This patch is basically an optimization for string::rfind(), and
> string::find_first_of(). It attempts to use different algorithms for
> either functions to speed up the operations of the functions in various
> situations. What I have done for find_first_of() is that there is a
> threshold(Paolo pointed out that the function will perform badly when
> the string passed as a parameter is >> *this, or when the string is too
> large, and the table build-up time is >> the normal case) of 128. Only
> if the string passed is <= 128 then will the optimized algorithm kick
> in. Else, the normal algorithm will be used.
>
> Also, I have one doubt: There is a line such as this:
>
> if (sizeof(char) <= 8 && (some other run-time condition))
> {
>
> }
> else
> {
>
> }
>
> Now, suppose that sizeof(char) > 8, will the optimizer eliminate the if
> block completely?
>
> Also, attached are test-cases used for measuring the timing of either of
> the functions before and after applying the patch. The file output.txt
> contains the timings reported by the above 2 tests before and after the
> application of the patch.
>
> Tested x86-Linux.
>
> However, these 2 seemingly unrelated tests are failing on the current
> cvs version:
>
> FAIL: 21_strings/basic_string/inserters_extractors/pod/10081-in.cc (test
> for excess errors)
> WARNING: 21_strings/basic_string/inserters_extractors/pod/10081-in.cc
> compilation failed to produce executable
> FAIL: 21_strings/basic_string/inserters_extractors/pod/10081-out.cc
> (test for excess errors)
> WARNING: 21_strings/basic_string/inserters_extractors/pod/10081-out.cc
> compilation failed to produce executable
>
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
template<typename Signature>
class CustomSignature : public Signature
{ };
-------------- next part --------------
*********Before patch************
[dhruv@localhost test]$ ./ffirst_of_test
5 Time taken == 0.07 seconds.
98 Time taken == 0.72 seconds.
47 Time taken == 0.36 seconds.
66 Time taken == 0.49 seconds.
3 Time taken == 0.04 seconds.
-1 Time taken == 0.61 seconds.
[dhruv@localhost test]$
[dhruv@localhost test]$ ./rfind_torture
Time taken: 5.17 seconds.
**********After patch**************
[dhruv@localhost test]$ ./ffirst_of_test
5 Time taken == 0.07 seconds.
98 Time taken == 0.18 seconds.
47 Time taken == 0.11 seconds.
66 Time taken == 0.13 seconds.
3 Time taken == 0.05 seconds.
-1 Time taken == 0.18 seconds.
[dhruv@localhost test]$
[dhruv@localhost test]$ ./rfind_torture
Time taken: 0.85 seconds.
More information about the Libstdc++
mailing list