LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Rather basic realization on scripting logic, it may be often better to let C programs do "excessive" work than trying to spare them w/ Bash

Posted 06-01-2023 at 12:29 PM by the dsc
Updated 06-01-2023 at 12:34 PM by the dsc

"C" stuff will be much faster than scripts, so sometimes even a "dumb" use of a C program will be more optimal (take less time) than trying to sort out a more minimal task for the C program with bash.

Like
Code:
 grep -h -m 1 THING-TO-GREP index_*
versus

Code:
 < ... some bash-script logic that tries to figure out the most likely index_NNNN files
 so grep has only to work with a few, not all ... > 

 grep -h -m 1 THING-TO-GREP ${most_likely_index_files}
I guess it will be quite rare that the solution that has more bash script stuff yields a better result, maybe scenarios where grep searching through all files could produce way more performance-bottlenecking hard disk reading, while a bash logic could circumvent that significantly.

Apparently the "logic" could be as rudimentary/basic as merely a loop that gives "grep" only a file to work at a time, and "breaking" the loop once the thing to be grepped is found (skipping needlessly searching other files), and still perform worse.
Posted in Uncategorized
Views 215 Comments 1
« Prev     Main     Next »
Total Comments 1

Comments

  1. Old Comment
    Mostly I use bash as a way to "glue" different (compiled) programs together. bash for quick changes, binaries for speed and for better string handling.
    Posted 06-06-2023 at 04:43 PM by jr_bob_dobbs jr_bob_dobbs is offline
 

  



All times are GMT -5. The time now is 08:16 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration