title: Bash vs Perl/Python: OS call perfomace
body: <p>Two scripts:</p>
  
  <p>Perl</p>
  
  <pre><code>use strict;
  use warnings;
  use utf8;
  
  while (1) {
     my $cmd = "echo bla | grep bla";
     system($cmd);
  }
  </code></pre>
  
  <p>Bash</p>
  
  <pre><code>while true;
  do echo bla | grep bla;
  done;
  </code></pre>
  
  <p>I'm getting a rather significant(about 10% on a single core) difference in CPU utilization. Any thoughts?</p>
  
  <p>Here's what I'm trying to troubleshoot: We have some legacy scripts written in Bash that run every X seconds. Upon inspection, we noticed that they consume a significant share of resources. After rewriting those scripts to Perl/Python the CPU utilization went down significantly. </p>
  
  <p>The Bash scripts heavily use calling external programs(awk,cut,grep,sed,etc.), while Perl/Python scripts were self-contained. I would attribute it to the fact that Bash forks/execs whenever it needs to create an external call, thus we are spending time creating thousands of processes. </p>