File: linetype_rendering.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 (42 lines) | stat: -rw-r--r-- 1,067 bytes parent folder | download | duplicates (2)
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
39
40
41
42
# Copyright (c) 2022, Manfred Moitzi
# License: MIT License
import time
from ezdxf.render._linetypes import _LineTypeRenderer as PyRenderer
from ezdxf.acc.linetypes import _LineTypeRenderer as CyRenderer


def dashed_lines(func, count):
    for _ in range(count):
        func()


def profile1(func, *args) -> float:
    t0 = time.perf_counter()
    func(*args)
    t1 = time.perf_counter()
    return t1 - t0


def py_rendering():
    r = PyRenderer((1., 1., 2., 1.))  # line-gap-line-gap
    list(r.line_segment((0, 0), (100, 0)))


def cy_rendering():
    r = CyRenderer((1., 1., 2., 1.))  # line-gap-line-gap
    list(r.line_segment((0, 0), (100, 0)))


def profile(text, func, *args):
    py_time = profile1(func, py_rendering, *args)
    print(f"CPython: {text} {py_time:.3f}s")
    cy_time = profile1(func, cy_rendering, *args)
    print(f"Cython: {text} {cy_time:.3f}s")
    print(f"Ratio CPython/Cython {py_time/cy_time:.1f}x\n")


RUNS = 40_000

print(f"Profiling linetype rendering implementations:")
profile(f"{RUNS} dashed lines: ", dashed_lines, RUNS)