

Libstdc++ has a "diagnostics" mode that suggests alternate containers - dhruvbird
http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt03ch19s07.html

======
asymptotic
The actual introduction page is far more enlightening:

[http://gcc.gnu.org/onlinedocs/libstdc++/manual/profile_mode....](http://gcc.gnu.org/onlinedocs/libstdc++/manual/profile_mode.html#manual.ext.profile_mode.intro)

The work is published under an application called "Perflint". Here's a link to
the PDF for the paper:

[http://0-portal.acm.org.millennium.lib.cyut.edu.tw/ft_gatewa...](http://0-portal.acm.org.millennium.lib.cyut.edu.tw/ft_gateway.cfm?id=1545076&type=pdf)

"Abstract—We present perflint, a new industrial strength open source analysis
tool that identifies suboptimal use patterns of the C++ standard library.
Simply by recompiling and running on a representative input set, programmers
receive context sensitive performance advice on their use of standard library
data structures and algorithms. Our solution consists of collecting traces of
relevant library operations and state during program execution, and then
recognizing patterns for which there is a faster alternative, based on a model
made of performance guarantees in the C++ language standard and machine
knowledge. perflint has already found hundreds of suboptimal patterns in a set
of large C++ benchmarks. In one case, following the advice and changing one
line of code resulted in 17% program run time reduction."

------
tom_b
I think it would be fun to think of this in a more high-level language where
data structures could be autonomously tuned by a VM or interpreter.

That way, you could start out with lists when prototyping and building up your
app, but under the covers, at runtime, your underlying data structure could
swap into something else that optimized your usage pattern. I also think that
although this idea sounds fun, that it is premature optimization of the worst
kind.

I do think that the idea of Perflint, where you do a little profiling up front
as the dev, is much better than trying to use some embedded heuristics.
Probably just realizing that its worth doing a little "real world data size"
testing makes something Perflint valuable.

~~~
lmz
Apple's CFArray does some of this. It can have different implementations
depending on the number of elements in it.[1] I don't think it observes the
usage pattern yet.

[1]: <http://ridiculousfish.com/blog/archives/2005/12/23/array/>

