Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from ctypes import *
from timeit import Timer
from random import randint
from collections import namedtuple
class Point(object):
x, y = None, None
def __init__(self, x, y):
self.x, self.y = x, y
class Point_ctypes(Structure):
_fields_ = [("x", c_int), ("y", c_int)]
class Point_slots(object):
def __init__(self, x, y):
self.x, self.y = x, y
def sum_(points):
for point in points:
return sum_x,sum_y
def rand_points(abs_point,n=10000):
return [abs_point(randint(0,1000),randint(0,1000)) for i in xrange(n)]
for i in (Point,Point_ctypes,Point_slots,Point_namedtuple):
print i.__name__,Timer('sum_(points)','from __main__ import sum_,points').timeit(number=1000)
# print i.__name__,Timer('sum([p.x for p in points]),sum([p.y for p in points])','from __main__ import sum_,points').timeit(number=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.