[Baypiggies] Discussion for newbies/beginner night talks - test results
Chad Netzer
chad.netzer at gmail.com
Thu Feb 15 23:21:39 CET 2007
On 2/15/07, Daniel Yoo <dyoo at cs.wpi.edu> wrote:
> To make this easier, we should change the defintions so that these are
> actual functions that can be compared functionally. For example:
>
> ##############################################
> def holding_with_lists():
> l = []
> for x in range(0,100000):
> l.append("abcdef")
> return ''.join(l)
>
> def holding_naive():
> l = ""
> for x in range(0,100000):
> l += "abcdef"
> return l
>
> assert holding_with_lists() == holding_naive()
> ##############################################
>
> Otherwise, without making sure these different implemenations return the
> same result, we risk comparing apples to oranges. I suspect that's what's
> happened here.
Danny, in addition to your good advice, I'd also suggest not using
range() in the loop, since Dennis was also intending to look at memory
footprint. Use xrange(), or make a simple iterator instead.
Dennis, you said in your example, "The final time.sleep(2000) is to
allow time for garbage collection to reduce memory usage." However,
that certainly will have no effect with CPython, nor do operating
system memory allocators work that way. If I'm wrong about this,
someone please enlighten me. You could try:
gc.collect()
but these simple examples probably don't have any unreachable memory
cycles. In general, memory usage benchmarking can be a tricky
undertaking, sometimes even for 'simple' examples.
Chad
More information about the Baypiggies
mailing list