def mm_func(x, y): return x + y @multimethods.multimethod(int, int) def mms_func(x, y): return x + y @multimethods.multimethod(float, float) def mms_func(x, y): return x + y @multimethods.multimethod(float, int) def mms_func(x, y): return x + y with timeit('pure'): for i in range(N): func(1, 2) with timeit('multidispatch'): for i in range(N): md_func(1, 2) with timeit('multimethod'): for i in range(N): mm_func(1, 2) with timeit('multimethods'): for i in range(N): mms_func(1, 2)
# -*- coding: utf8 -*- ''' Semelhante ao gas_aabbs.py, mas desta vez utiliza objetos da classe Poly. ''' from FGAme import * from random import uniform # Constantes da simulação SPEED = 300 SHAPE = (30, 30) NUM_POLYS = 50 # Inicializa o mundo world = World(gravity=50, dfriction=0) world.add_bounds(width=10) # Preenche o mundo for _ in range(NUM_POLYS): pos = Vec2(uniform(30, 770), uniform(30, 570)) vel = Vec2(uniform(-SPEED, SPEED), uniform(-SPEED, SPEED)) obj = Rectangle(shape=SHAPE, vel=vel, pos=pos, color=(200, 0, 0)) world.add(obj) # Inicia a simulação import fasttrack with fasttrack.timeit('foo'): world.run()