Source

bubble-economy / time_nearness_acc.py

from setup_args import setup_args
import pyximport; pyximport.install(setup_args=setup_args)
import scipy as sp
import numpy as np
import scipy.spatial.distance as distance
import spanning_tree
from numpy.testing import assert_array_equal, TestCase
from scipy.spatial import distance
import nearness
import nearness_acc
import test_nearness_acc
import time
from pprint import pprint

METHODS_TO_TEST = (
    ('pure python', nearness.neighbours),
    ('plain cython', nearness_acc.neighbours_p_norm),
    ('2-norm cython', nearness_acc._neighbours_2_norm_64),
    ('2-norm 32 bit cython', nearness_acc.neighbours_2_norm_32),
)
SIZE=3000
RADIUS=0.1

def time_test(size, radius):
    locs = test_nearness_acc.create_particles(size)
    rez = []
    times = []
    method_string = []
    for method_name, method in METHODS_TO_TEST:
        method_string.append(method_name)
        t = time.clock()
        rez.append(method(locs, radius))
        times.append(time.clock()-t)
    pprint(zip(method_string, times))
    
if __name__=='__main__':
    time_test(SIZE, RADIUS)