Something about sizeof(char)

Dhruv Matani dhruvbird@gmx.net
Mon Jun 14 16:58:00 GMT 2004


Hi,
	I have attached a test case that compares the performance of the
traditional approach as used in string::find_first_of(), and a different
approach as in the function ffirst_of().

The newer approach uses a temporary stachk array of size 1 <<
__CHAR_BIT__ if __CHAR_BIT__ <= 8, and then performs the operation,
which makes the worst case complexity come down from O(n*m) to O(n+m),
which is an improvement.

I'm not too good at figuring out whether code is portable or not, so I'm
not rally sure that this would be acceptable, so I'd like to hear from
the experts.


On Mon, 2004-06-14 at 21:04, Paolo Carlini wrote:
> Dhruv Matani wrote:
> 
> >Hi,
> >	Is there any way of knowing whether on a platform the sizeof(char)
> >being always one is actually one byte == 8-bits? Or 1 is defined as more
> >than 8-bits.
> >  
> >
> For this there is the predefined macro |__CHAR_BIT__|
> 
> Paolo.
-- 
        -Dhruv Matani.
http://www.geocities.com/dhruvbird/

Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ffirst_of_test.cpp
Type: text/x-c++
Size: 1607 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040614/3563db7b/attachment.bin>
-------------- next part --------------
[dhruv@localhost test]$ ./ffirst_of_test 
5 Time taken == 0.05 seconds.
5 Time taken == 0.04 seconds.

98 Time taken == 0.55 seconds.
98 Time taken == 0.14 seconds.

47 Time taken == 0.27 seconds.
47 Time taken == 0.09 seconds.

66 Time taken == 0.36 seconds.
66 Time taken == 0.11 seconds.

3 Time taken == 0.03 seconds.
3 Time taken == 0.04 seconds.

-1 Time taken == 0.46 seconds.
-1 Time taken == 0.15 seconds.

[dhruv@localhost test]$ 


More information about the Libstdc++ mailing list