aheadlead
V2EX  ›  问与答

grep 黑科技为何扫描速度比我 ssd 还快?

  •  
  •   aheadlead · Dec 24, 2014 · 3181 views
    This topic created in 4198 days ago, the information mentioned may be changed or developed.
    我用dd从/dev/random弄了409M数据出来

    然后马上用grep二进制匹配一个子串
    套上time命令
    $time /usr/local/Cellar/grep/2.20/bin/grep -oba 'vv' test > result.txt

    real 0m0.424s
    user 0m0.242s
    sys 0m0.113s

    这...是为何?
    3 replies    2014-12-24 03:20:53 +08:00
    efi
        1
    efi  
       Dec 24, 2014
    echo 3 > /proc/sys/vm/drop_caches
    dreampuf
        2
    dreampuf  
       Dec 24, 2014
    除了磁盘缓存,GREP本身足够高效

    为什么GNU grep如此之快?
    http://www.kuqin.com/shuoit/20131205/336792.html
    lhbc
        3
    lhbc  
       Dec 24, 2014
    读取过一次的东西在内存里
    不信你 dd 一个 1G 文件到 /dev/null,再次 dd 能达到 3-5 GB/s 的速度
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5575 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 81ms · UTC 07:56 · PVG 15:56 · LAX 00:56 · JFK 03:56
    ♥ Do have faith in what you're doing.