Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 753059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:51:13+00:00 2026-05-14T14:51:13+00:00

I wrote multiple scripts in Perl and shell and I have compared the real

  • 0

I wrote multiple scripts in Perl and shell and I have compared the real execution time. In all the cases, the Perl script was more than 10 times faster than the shell script.

So I wondered if it possible to write a shell script which is faster than the same script in Perl? And why is Perl faster than shell although I use the system function in Perl script?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:51:13+00:00Added an answer on May 14, 2026 at 2:51 pm

    There are few ways to make your shell (eg Bash) execute faster.

    1. Try to use less of external commands if Bash’s internals can do the task
      for you. Eg, excessive use of sed , grep, awk et for string/text
      manipulation.
    2. If you are manipulating relatively BIG files, don’t use bash’s while read loop.
      Use awk. If you are manipulating really BIG files, you can use grep to search for the patterns you want, and then pass them to awk to “edit”. grep’s searching algorithm is very good and fast. If you want to get only front or end of the file, use head and tail.
    3. file manipulation tools such as sed, cut, grep, wc, etc all can be done
      with one awk script or using Bash internals if not complicated. Therefore, you can try to cut down the use of these tools that overlap in their functions.
      Unix pipes/chaining is excellent, but using too many of them,
      eg
      command|grep|grep|cut|sed makes your code slow. Each pipe is an overhead.
      For this example, just one awk does them all.
      command | awk '{do everything here}'
      The closest tool you can use which can match Perl’s speed for certain tasks, eg string manipulation or maths, is awk. Here’s a fun benchmark for this solution. There are around 9million numbers in the file

    Output

    $ head -5 file
    1
    2
    3
    34
    42
    $ wc -l <file
    8999987
    
    # time perl -nle '$sum += $_ } END { print $sum' file
    290980117
    
    real    0m13.532s
    user    0m11.454s
    sys     0m0.624s
    
    $ time awk '{ sum += $1 } END { print sum }' file
    290980117
    
    real    0m9.271s
    user    0m7.754s
    sys     0m0.415s
    
    $ time perl -nle '$sum += $_ } END { print $sum' file
    290980117
    
    real    0m13.158s
    user    0m11.537s
    sys     0m0.586s
    
    $ time awk '{ sum += $1 } END { print sum }' file
    290980117
    
    real    0m9.028s
    user    0m7.627s
    sys     0m0.414s
    

    For each try, awk is faster than Perl.

    Lastly, try to learn awk beyond what they can do as one liners.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 465k
  • Answers 465k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer By using the remote => true on the form, your… May 16, 2026 at 1:22 am
  • Editorial Team
    Editorial Team added an answer PyTables is a package for managing hierarchical datasets. It is… May 16, 2026 at 1:22 am
  • Editorial Team
    Editorial Team added an answer ASP.NET tips: Golden rules for Dynamic Controls. May 16, 2026 at 1:22 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.