File: load_file_structure_index.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 (40 lines) | stat: -rw-r--r-- 1,268 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
39
40
# Copyright (c) 2020-2022, Manfred Moitzi
# License: MIT License
import pathlib
import time
import ezdxf
from ezdxf.lldxf.fileindex import load

CADKIT = pathlib.Path(ezdxf.EZDXF_TEST_FILES) / "CADKitSamples"

# ------------------------------------------------------------------------------
# create FileStructure instances from CADKitSamples
#
# This example shows how fast Python can load DXF files without interpretation,
# this marks the lower bound for loading optimizations.
# ------------------------------------------------------------------------------


def main():
    overall_time = 0.0
    overall_lines = 0
    for name in CADKIT.glob("*.dxf"):
        t0 = time.perf_counter()
        file_structure = load(str(name))
        t = time.perf_counter() - t0
        count = sum(t.code == 0 for t in file_structure.index)
        lines = file_structure.index[-1].line
        overall_time += t
        overall_lines += lines
        print(
            f'File: "{pathlib.Path(name).name}"\n  {lines} '
            f"lines scanned\n  {count} "
            f"structure tags\n  scan time: {t:.2f}s\n"
        )

    print(f"Overall time to scan: {overall_time:.2f}s")
    print(f"Overall scanned lines: {overall_lines}")


if __name__ == "__main__":
    main()