File: tag_compiler.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 (34 lines) | stat: -rw-r--r-- 833 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
#  Copyright (c) 2020-2022, Manfred Moitzi
#  License: MIT License
import time
import ezdxf
from ezdxf.lldxf.tagger import ascii_tags_loader, tag_compiler
from ezdxf.recover import safe_tag_loader

BIG_FILE = ezdxf.options.test_files_path / "CADKitSamples" / "torso_uniform.dxf"


def load_ascii():
    with open(BIG_FILE, "rt") as fp:
        list(tag_compiler(iter(ascii_tags_loader(fp))))


def safe_load_bytes():
    with open(BIG_FILE, "rb") as fp:
        list(safe_tag_loader(fp))


def print_result(time, text):
    print(f"Operation: {text} takes {time:.2f} s\n")


def run(func):
    start = time.perf_counter()
    func()
    end = time.perf_counter()
    return end - start


if __name__ == "__main__":
    print_result(run(safe_load_bytes), "safe_tag_loader()")
    print_result(run(load_ascii), "ascii_tag_compiler()")