File: bspline_point_calculation.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (38 lines) | stat: -rw-r--r-- 943 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Copyright (c) 2020-2024, Manfred Moitzi
# License: MIT License
import time
import math
import numpy as np

from ezdxf.math import global_bspline_interpolation
from ezdxf.render import random_3d_path

path = list(random_3d_path(100, max_step_size=10, max_heading=math.pi * 0.8))
spline = global_bspline_interpolation(path)


def profile_bspline_point_new(count, spline):
    for _ in range(count):
        for t in np.linspace(0, 1.0, 100):
            spline.point(t)


def profile_bspline_derivatives_new(count, spline):
    for _ in range(count):
        list(spline.derivatives(t=np.linspace(0, 1.0, 100)))


def profile(text, func, *args):
    t0 = time.perf_counter()
    func(*args)
    t1 = time.perf_counter()
    print(f"{text} {t1 - t0:.3f}s")


profile("B-spline point new 300x: ", profile_bspline_point_new, 300, spline)
profile(
    "B-spline derivatives new 300x: ",
    profile_bspline_derivatives_new,
    300,
    spline,
)