# Copyright (c) 2013-2014 Bartosz Szczesny <bszcz@bszcz.org>
# This program is free software under the MIT license.

# memory usage in MB with 1e6 points
#
# useSlots  python2.7.6  python3.4.0
# ----------------------------------
# False     ~375         ~175
# True      ~105         ~75

class Point(object):
	def __init__(self, x, y, z):
		self.x = x
		self.y = y
		self.z = z

class PointWithSlots(object):
	__slots__ = ('x', 'y', 'z')
	def __init__(self, x, y, z):
		self.x = x
		self.y = y
		self.z = z
def main():
	useSlots = False
	numPoints = int(1e6)
	print("Allocating memory...")
	points = malloc(numPoints, useSlots)
	try:
		input("Done, press Enter to exit.")
	except SyntaxError:
		pass
	# switch to another terminal at this point,
	# use 'ps' (or 'htop') to check memory usage
	# with and without __slots__, then hit 'Enter'


def malloc(numPoints, useSlots):
	points = []
	if useSlots:
		for i in range(numPoints):
			points.append(PointWithSlots(1, 2, 3))
	else:
		for i in range(numPoints):
			points.append(Point(1, 2, 3))
	return points

if __name__ == "__main__":
	main()
