V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wohenfuyou
V2EX  ›  Python

各位彦祖, Python 用哪个加载 xml 文件比较快

  •  
  •   wohenfuyou · 2021-05-12 15:16:57 +08:00 · 1420 次点击
    这是一个创建于 1051 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用了 xml.dom.minidom,加载个 100M 的 XM 的文件用了 60s,好慢

    6 条回复    2021-05-13 08:48:03 +08:00
    no1xsyzy
        1
    no1xsyzy  
       2021-05-12 15:28:10 +08:00   ❤️ 1
    https://lxml.de/performance.html

    目前通常认为是 lxml 最快
    wellsc
        2
    wellsc  
       2021-05-12 15:29:01 +08:00
    换语言
    imn1
        3
    imn1  
       2021-05-12 15:46:54 +08:00   ❤️ 2
    100M 的应该什么语言都用流式解析吧,整体加载 DOM 太大了,非常耗资源
    找 xml parser 相关的库,例如 sax
    abersheeran
        4
    abersheeran  
       2021-05-12 22:20:49 +08:00 via Android
    @no1xsyzy 提到这玩意儿。我想起来以前写一个页面解析的时候,用 docker 跑的,阿里云 Serverless 上 lxml 怎么都解析不出来,我本机次次跑都没问题,最后还是换了 html.parser 。
    ALLROBOT
        5
    ALLROBOT  
       2021-05-13 08:29:47 +08:00
    用 C/C++最快

    python 执行速度比它们慢多了
    wohenfuyou
        6
    wohenfuyou  
    OP
       2021-05-13 08:48:03 +08:00
    改用 c++ tinyxml2 了 就 2s 钟,差距也太大了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5671 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 01:44 · PVG 09:44 · LAX 18:44 · JFK 21:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.