File: numpy_cython_support.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-- 919 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) 2023, Manfred Moitzi
# License: MIT License
import time
import numpy as np
from ezdxf.math import Vec2, has_clockwise_orientation
from ezdxf.acc import np_support
from ezdxf.render.forms import circle


VEC2_LIST = Vec2.list(circle(512, 10, close=True))
NP_ARRAY = np.array(VEC2_LIST, dtype=np.float64)


def has_cw_vec2():
    has_clockwise_orientation(VEC2_LIST)


def has_cw_numpy():
    np_support.has_clockwise_orientation(NP_ARRAY)


def profile(text, func, runs):
    t0 = time.perf_counter()
    for _ in range(runs):
        func()
    t1 = time.perf_counter()
    t = t1 - t0
    print(f"{text} {t:.3f}s")


RUNS = 100_000

print(f"Profiling Cython support module for numpy arrays:")
print(
    f"Test array has {len(VEC2_LIST)} vertices."
)
profile(f"has_clockwise_orientation() Vec2 {RUNS}:", has_cw_vec2, RUNS)
profile(f"np_support.has_clockwise_orientation() {RUNS}:", has_cw_numpy, RUNS)