60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""
|
|
Benchmarking, run with `python3 -m adze.test.benchmark`
|
|
|
|
TODO: Consider using pytest-benchmark?
|
|
"""
|
|
import warnings
|
|
from time import perf_counter
|
|
import random
|
|
import logging
|
|
|
|
import numpy # type: ignore
|
|
from numpy import sin, cos, pi
|
|
from numpy.linalg import norm # type: ignore
|
|
|
|
import adze
|
|
import adze.util
|
|
|
|
from .utils import TOL_FAIL, TOL_WARN, PRNG, MIN_VOLUME, flip_plane, tetrahedron_volume
|
|
from .utils import build_rand_tetrahedron, plane_generators, rand_tetrahedron_vertices
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def test_split(benchmark):
|
|
poly = build_rand_tetrahedron()
|
|
faceset = adze.planes_from_tetrahedron(rand_tetrahedron_vertices())
|
|
benchmark(adze.clip, poly, faceset[0])
|
|
|
|
|
|
def test_split_bulk_1000(benchmark):
|
|
NUM_TRIALS = 1000
|
|
polys_bulk = [build_rand_tetrahedron() for _ in range(NUM_TRIALS)]
|
|
faceset = adze.planes_from_tetrahedron(rand_tetrahedron_vertices())
|
|
bulk = {
|
|
'vertices': numpy.vstack([p['vertices'] for p in polys_bulk]),
|
|
'neighbors': numpy.vstack([p['neighbors'] for p in polys_bulk]) + numpy.arange(NUM_TRIALS).repeat(4)[:, None] * 4,
|
|
}
|
|
benchmark(adze.clip, bulk, faceset[0])
|
|
|
|
|
|
|
|
def get_intersection_moments(poly, faces, poly_order):
|
|
# Clip the first tetrahedron using the faces of the second
|
|
for face in faces:
|
|
poly = adze.clip(poly, face)
|
|
|
|
# find the moments (up to quadratic order) of the clipped poly
|
|
om = adze.get_moments(poly, poly_order)
|
|
return om
|
|
|
|
|
|
def test_intersection(benchmark, poly_order=0):
|
|
"""
|
|
Benchmark intersection between pairs of tetrahedra
|
|
"""
|
|
poly = build_rand_tetrahedron()
|
|
faces = adze.planes_from_tetrahedron(rand_tetrahedron_vertices())
|
|
benchmark(get_intersection_moments, poly, faces, poly_order)
|
|
|