V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
334862132
V2EX  ›  Python

查询时候每次都拼接和直接拼接好哪种性能更换

  •  
  •   334862132 · Apr 18, 2019 · 2214 views
    This topic created in 2578 days ago, the information mentioned may be changed or developed.
    每次查询的时候都拼接一千行字符串性能好
    还是直接把俩千行字符串都拼接好每次直接调用性能好(查询会频繁调用)

    最近在研究过去的代码,发现有两页各一千多行的变量代码都是全局变量 加 一个函数结果 拼接成的新全局变量,
    代码在不停的引用俩个页面里面的变量
    我最近在想要不要把这个俩个页面合成一个界面
    之后每次查询的时候直接传入新的函数进行拼接,
    类型不可能变多的,因为一个是今日,一个是总计
    2 replies    2019-04-18 11:34:36 +08:00
    xpresslink
        1
    xpresslink  
       Apr 18, 2019   ❤️ 1
    总的原则是尽量减少数据库交互操作,因为数据库 io 最快也要毫秒级别,特别是还要网络传输的情况。
    lihongjie0209
        2
    lihongjie0209  
       Apr 18, 2019   ❤️ 1
    优化前: 数据库查询 100ms 拼接字符串 10ms 开发人员耗时 0 min 测试人员耗时 0 min
    瞎优化: 数据库查询 100ms 拼接字符串 12ms 开发人员耗时 30min 测试人员耗时 30min
    真优化: 数据库查询 100ms 拼接字符串 8 ms 开发人员耗时 3 h 测试人员耗时 30min
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1063 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:26 · PVG 02:26 · LAX 11:26 · JFK 14:26
    ♥ Do have faith in what you're doing.