Neil Cerutti wrote: > I don't see why it should run a lot faster that way. > > Appending elements to a vector with push_back takes amortized > constant time. In the example above, preallocating 40000 strings > saves (probably) math.log(40000, 2) reallocations of the vector's > storage along with the consequent copy-construction and > destruction of some fixed number of strings. Most of those > reallocations take place while the vector is still proportionally > quite small.
I see your logic, however it does make it run a lot faster. On my machine, with 1000000 repetition, what used to take 5+ seconds now takes only about 1+++ to 2 secs. > > -- > Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list