Skip to content

Instantly share code, notes, and snippets.

@lily-mara
Created February 12, 2015 18:22
Show Gist options
  • Save lily-mara/e84c14966384c428a3d8 to your computer and use it in GitHub Desktop.
Save lily-mara/e84c14966384c428a3d8 to your computer and use it in GitHub Desktop.
Zero-Cost Abstraction
class Sum(object):
def __init__(self):
self._sum = 0
def increment(self, val):
self._sum += val
def print_sum(self):
print self._sum
s = Sum()
for i in range(1, 1000001):
s.increment(i)
s.print_sum()
sum = 0
for i in range(1, 1000001):
sum += i
print sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment