30

File manager nnn takes half the time taken by ls to list

 4 years ago
source link: https://www.tuicool.com/articles/hit/RzaE7nv
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

COMPARISON

Stripped binary (or script) size and memory usage of nnn and some other popular FMs (which existed before nnn ) while viewing a directory with 13.5K files (0 directories), sorted by size/du:

<b>BINSZ</b>    VIRT  <b>  RES</b>    SHR S  %MEM   COMMAND
<b> 650K</b>  139720  <b>91220</b>   8460 S   1.1   ranger
<b>   1M</b>   50496  <b>15328</b>   4076 S   0.2   vifm
<b>   1M</b>   72152  <b>12468</b>   7336 S   0.2   mc
<b>  55K</b>   15740  <b> 4348</b>   2460 S   0.1   nnn -S

NNN VS. LS

In a sample one-shot run, nnn took less than 50% time to list a directory with 2083 files:

$ time nnn /usr/bin
0.00user 0.04system 0:00.04elapsed 97%CPU (0avgtext+0avgdata 3588maxresident)k
0inputs+0outputs (0major+544minor)pagefaults 0swaps

$ time ls -l /usr/bin
0.02user 0.08system 0:00.09elapsed 117%CPU (0avgtext+0avgdata 3696maxresident)k
0inputs+0outputs (0major+527minor)pagefaults 0swaps

OPTIMIZATION

nnn uses highly optimized algorithms. Some of the significant factors are listed below:

O3
-Wall -Wextra -Werror

However, we had been most careful not to obfuscate the code. It's reasonably well-documented too!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK