Skip to content

Instantly share code, notes, and snippets.

@pilt
Created August 11, 2011 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilt/1140553 to your computer and use it in GitHub Desktop.
Save pilt/1140553 to your computer and use it in GitHub Desktop.
multipled = [3 * s for s in series]
calls = 0
multipled = []
for n in series:
calls += 1
multipled.append(3 * n)
print "%d calls" % calls
class CallCounting(object):
def __init__(self, func):
self.count = 0
self.func = func
def __call__(self, *args, **kwargs):
self.count += 1
return self.func(*args, **kwargs)
timesthree = CallCounting(lambda x: 3 * x)
multipled = [timesthree(n) for n in series]
print "%d calls" % timesthree.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment