Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

python-importtime-graph

Posted on 2025-06-21

python-importtime-graph

我正在研究为什么一个 Python 工具需要一秒钟以上才能开始运行,然后我了解了python -X importtime功能,该功能在此处有记录。添加该选项会导致 Python 输出一个文本树,显示导入每个模块所花费的时间。

我尝试过这样:

 python -X importtime -m llm plugins

这是LLM运行 41 个不同插件时的结果。以下是该命令的完整输出,其开头如下:

 import time: self [us] | cumulative | imported package import time: 77 | 77 | _io import time: 19 | 19 | marshal import time: 131 | 131 | posix import time: 363 | 590 | _frozen_importlib_external import time: 450 | 450 | time import time: 110 | 559 | zipimport import time: 64 | 64 | _codecs import time: 252 | 315 | codecs import time: 277 | 277 | encodings.aliases

Kevin Michel 构建了这个出色的工具,用于将这些轨迹可视化为树状图。它可以在浏览器中运行 – 访问kmichel.github.io/python-importtime-graph/并粘贴轨迹即可获得可视化效果。

以下是我对 LLM 示例跟踪的描述:

难以辨认的密集树状图

可以看到,内容非常丰富!这是SVG 版本,可读性更强,因为你可以放大查看各个部分。

放大后看起来像这样:

性能分析树状图可视化显示了 Python 库和模块的执行时间,其中彩色矩形块的大小与其执行时间成比例,顶部显示“总计:2845.828 毫秒”,主要组成部分包括“lim.cli:2256.275 毫秒”和“openai:150.043 毫秒”

标签:性能、 python 、可视化

原文: https://simonwillison.net/2025/Jun/20/python-importtime-graph/#atom-everything

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Bits about Money
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Colin Percival
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Dustin Curtis
  • eighty twenty
  • Elad Gil
  • Ellie Huxtable
  • Ethan Dalool
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • Henrique Dias
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Liz Danzico
  • Lou Plummer
  • Luke Wroblewski
  • Matt Baer
  • Matt Stoller
  • Matthias Endler
  • Mert Bulan
  • Mostly metrics
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Rohit Patel
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Steve Blank
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • Understanding AI
  • Wes Kao
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme