public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/51078] New: [PATCH] performance improvement of std::count algorithm
@ 2011-11-10 11:40 grygoriy.fuchedzhy at gmail dot com
  2011-11-10 11:41 ` [Bug libstdc++/51078] " grygoriy.fuchedzhy at gmail dot com
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: grygoriy.fuchedzhy at gmail dot com @ 2011-11-10 11:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51078

             Bug #: 51078
           Summary: [PATCH] performance improvement of std::count
                    algorithm
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: grygoriy.fuchedzhy@gmail.com


Created attachment 25778
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25778
patch itself

This patch improves performance of std::count algorithm in case of random
access iterators by loop unrolling. It doesn't affect std::count algorithm for
usual input iterators. This is done by choosing different versions of function
for different iterator types at compile time, similar technique is used for
std::find algorithm.

Besides the patch itself I've attached performance test which can be used to
test this changes without even applying them. Test program has count_local
function which implements improvements of this patch. Test program generates
test bunch of test containers of different types and performs count_local and
original count algorithm on them. It outputs table with following columns:
container_size, type1_local_time, type1_orig_time, type1_performance_boost,
type2_local_time, type2_orig_time, type2_performance_boost, ...

container_size is length of data passed to each call to count algorithm.
typeX_local_time is time elapsed counting bunch of containers of type X using
count_local function.
typeX_orig_time is time elapsed counting bunch of containers of type X using
original count implementation.
typeX_performance_boost is (typeX_orig_time -
typeX_local_time)/typeX_orig_time.
Number of containers for testing decreases with increasing of container_size to
keep testing time relatively constant.

There is also data file containing test results and gnuplot script to plot
them. Results were obtained on my machine with i7 cpu. Also tried another
machine with core2 processor, got similar results. Also tried changing range of
generated random data from [1-128] to [1-2]. Got similar results.

I also attached plots of performance boost against container size, first one is
linear by size, second one is logarithmic.

As you can see there is performance decrease for very small containers with
length less then 10 elements. And around 30% performance boost for larger
containers with fundamental types. Containers of complex data
vector<vector<int> > have small performace boost around 1%.

There is also list<int> to demonstrate that this patch doesn't affect non
random access iterators.


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2011-11-15 10:52 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-10 11:40 [Bug libstdc++/51078] New: [PATCH] performance improvement of std::count algorithm grygoriy.fuchedzhy at gmail dot com
2011-11-10 11:41 ` [Bug libstdc++/51078] " grygoriy.fuchedzhy at gmail dot com
2011-11-10 11:42 ` grygoriy.fuchedzhy at gmail dot com
2011-11-10 11:43 ` grygoriy.fuchedzhy at gmail dot com
2011-11-10 11:56 ` grygoriy.fuchedzhy at gmail dot com
2011-11-10 12:01 ` grygoriy.fuchedzhy at gmail dot com
2011-11-10 12:05 ` redi at gcc dot gnu.org
2011-11-10 14:23 ` grygoriy.fuchedzhy at gmail dot com
2011-11-10 17:35 ` marc.glisse at normalesup dot org
2011-11-10 18:11 ` grygoriy.fuchedzhy at gmail dot com
2011-11-10 18:31 ` paolo.carlini at oracle dot com
2011-11-11 22:36 ` grygoriy.fuchedzhy at gmail dot com
2011-11-11 22:37 ` grygoriy.fuchedzhy at gmail dot com
2011-11-11 23:36 ` paolo.carlini at oracle dot com
2011-11-12 12:12 ` grygoriy.fuchedzhy at gmail dot com
2011-11-12 12:14 ` paolo.carlini at oracle dot com
2011-11-12 12:22 ` paolo.carlini at oracle dot com
2011-11-12 12:32 ` paolo.carlini at oracle dot com
2011-11-12 13:12 ` paolo.carlini at oracle dot com
2011-11-12 13:21 ` paolo.carlini at oracle dot com
2011-11-15 10:58 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).