Optimize Strings_startWith()

Use strncmp() combined with a strlen() will give better performance
than a strstr in worst case. Especially when the match prefix is a
constant and not a variable.

While we are at it, replace the match() function in linux/Battery.c,
which uses a naive algorithm, with a macro that does better job by
utilizing Strings_startWith().

    $ gcc --version | head -n 1
    gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
    $ uname -m
    x86_64
    $ size htop.old htop.new
       text   data    bss    dec    hex filename
     137929  15112   3776 156817  26491 htop.old
     137784  15104   3776 156664  263f8 htop.new

Signed-off-by: Kang-Che Sung <explorer09 @ gmail.com>
4 files changed
tree: aa805f4b034262f515352863a943c87fcc0954bf
  1. .editorconfig
  2. .gitignore
  3. .travis.yml
  4. AUTHORS
  5. Action.c
  6. Action.h
  7. Affinity.c
  8. Affinity.h
  9. AffinityPanel.c
  10. AffinityPanel.h
  11. AvailableColumnsPanel.c
  12. AvailableColumnsPanel.h
  13. AvailableMetersPanel.c
  14. AvailableMetersPanel.h
  15. BatteryMeter.c
  16. BatteryMeter.h
  17. COPYING
  18. CPUMeter.c
  19. CPUMeter.h
  20. CRT.c
  21. CRT.h
  22. CategoriesPanel.c
  23. CategoriesPanel.h
  24. ChangeLog
  25. CheckItem.c
  26. CheckItem.h
  27. ClockMeter.c
  28. ClockMeter.h
  29. ColorsPanel.c
  30. ColorsPanel.h
  31. ColumnsPanel.c
  32. ColumnsPanel.h
  33. DisplayOptionsPanel.c
  34. DisplayOptionsPanel.h
  35. EnvScreen.c
  36. EnvScreen.h
  37. FunctionBar.c
  38. FunctionBar.h
  39. Hashtable.c
  40. Hashtable.h
  41. Header.c
  42. Header.h
  43. HostnameMeter.c
  44. HostnameMeter.h
  45. INSTALL
  46. IncSet.c
  47. IncSet.h
  48. InfoScreen.c
  49. InfoScreen.h
  50. ListItem.c
  51. ListItem.h
  52. LoadAverageMeter.c
  53. LoadAverageMeter.h
  54. MainPanel.c
  55. MainPanel.h
  56. Makefile.am
  57. MemoryMeter.c
  58. MemoryMeter.h
  59. Meter.c
  60. Meter.h
  61. MetersPanel.c
  62. MetersPanel.h
  63. NEWS
  64. Object.c
  65. Object.h
  66. OpenFilesScreen.c
  67. OpenFilesScreen.h
  68. Panel.c
  69. Panel.h
  70. Process.c
  71. Process.h
  72. ProcessList.c
  73. ProcessList.h
  74. README
  75. RichString.c
  76. RichString.h
  77. ScreenManager.c
  78. ScreenManager.h
  79. Settings.c
  80. Settings.h
  81. SignalsPanel.c
  82. SignalsPanel.h
  83. StringUtils.c
  84. StringUtils.h
  85. SwapMeter.c
  86. SwapMeter.h
  87. TESTPLAN
  88. TasksMeter.c
  89. TasksMeter.h
  90. TraceScreen.c
  91. TraceScreen.h
  92. UptimeMeter.c
  93. UptimeMeter.h
  94. UsersTable.c
  95. UsersTable.h
  96. Vector.c
  97. Vector.h
  98. XAlloc.c
  99. XAlloc.h
  100. autogen.sh
  101. configure.ac
  102. darwin/
  103. freebsd/
  104. htop.1.in
  105. htop.c
  106. htop.desktop
  107. htop.h
  108. htop.png
  109. linux/
  110. openbsd/
  111. scripts/
  112. test_spec.lua
  113. unsupported/
README.md

Build Status PayPal donate

htop

by Hisham Muhammad hisham@gobolinux.org (2004 - 2016)

Introduction

This is htop, an interactive process viewer. It requires ncurses. It is developed primarily on Linux, but we also have code for running under FreeBSD and Mac OS X (help and testing are wanted for these platforms!)

This software has evolved considerably over the years, and is reasonably complete, but there is always room for improvement.

Comparison between htop and classic top

  • In htop you can scroll the list vertically and horizontally to see all processes and full command lines.
  • In top you are subject to a delay for each unassigned key you press (especially annoying when multi-key escape sequences are triggered by accident).
  • htop starts faster (top seems to collect data for a while before displaying anything).
  • In htop you don't need to type the process number to kill a process, in top you do.
  • In htop you don't need to type the process number or the priority value to renice a process, in top you do.
  • In htop you can kill multiple processes at once.
  • top is older, hence, more tested.

Compilation instructions

This program is distributed as a standard autotools-based package. See the INSTALL file for detailed instructions.

When compiling from a release tarball, run:

./configure && make

For compiling sources downloaded from the Git repository, run:

./autogen.sh && ./configure && make

By default make install will install into /usr/local, for changing the path use ./configure --prefix=/some/path.

See the manual page (man htop) or the on-line help (‘F1’ or ‘h’ inside htop) for a list of supported key commands.

If not all keys work check your curses configuration.

License

GNU General Public License, version 2 (GPL-2.0)