Re: STL speed
"Przemo Drochomirecki" <pedrosch@gazet a.pl> skrev i en meddelelse
news:btkn1f$d4h $1@nemesis.news .tpi.pl...[color=blue]
> Hi,
> The task was indeed simple. Read 2.000.000 words (average length = 9),[/color]
sort[color=blue]
> them and write it to new file.
> I've made this in STL, and it was almost 17 times slower than my previous
> "clear-C-code".
> I used <vector>, <algorithm>, <iostream> and <algorithm>. Is STL really so
> slow?
>
> Thx in adv.
> Przemo
>
> p.s. i know that STL uses IntrospectiveSo rt which seems to be good choice,[/color]
i[color=blue]
> suppose that INPUT (cin) is extremaly slow,
> and <vector> as a dynamic structure also isn't to fast... any ideas?
>
>[/color]
Hi Przemo
Some general comments. First it seems that the Microsoft
stream-implementation is not very good. The penalty of using streams
compared to C file I/O is significant in your example - giving (if i
remember correctly) a factor of four in performance. For GCC streams should
have the same performance as C file I/O.
Secondly, when compiling C++ optimization is far more important than in C.
So if you do not optimize your program you can be quite certain it will be
slow - a factor of say 5 or 17 should not be surprising at all.
Thirdly, your implementation is sub-optimal as pointed out by others.
With VC++ 6.0 (which from an optimization point of view isnt that bad), the
performance of <vector> should be comparable to the C-way of doing things -
and your sort should be much faster.
Kind regards
Peter
"Przemo Drochomirecki" <pedrosch@gazet a.pl> skrev i en meddelelse
news:btkn1f$d4h $1@nemesis.news .tpi.pl...[color=blue]
> Hi,
> The task was indeed simple. Read 2.000.000 words (average length = 9),[/color]
sort[color=blue]
> them and write it to new file.
> I've made this in STL, and it was almost 17 times slower than my previous
> "clear-C-code".
> I used <vector>, <algorithm>, <iostream> and <algorithm>. Is STL really so
> slow?
>
> Thx in adv.
> Przemo
>
> p.s. i know that STL uses IntrospectiveSo rt which seems to be good choice,[/color]
i[color=blue]
> suppose that INPUT (cin) is extremaly slow,
> and <vector> as a dynamic structure also isn't to fast... any ideas?
>
>[/color]
Hi Przemo
Some general comments. First it seems that the Microsoft
stream-implementation is not very good. The penalty of using streams
compared to C file I/O is significant in your example - giving (if i
remember correctly) a factor of four in performance. For GCC streams should
have the same performance as C file I/O.
Secondly, when compiling C++ optimization is far more important than in C.
So if you do not optimize your program you can be quite certain it will be
slow - a factor of say 5 or 17 should not be surprising at all.
Thirdly, your implementation is sub-optimal as pointed out by others.
With VC++ 6.0 (which from an optimization point of view isnt that bad), the
performance of <vector> should be comparable to the C-way of doing things -
and your sort should be much faster.
Kind regards
Peter
Comment