LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2010, 05:10 PM   #1
hashbang#!
Member
 
Registered: Aug 2009
Location: soon to be independent Scotland
Distribution: Debian
Posts: 120

Rep: Reputation: 17
[bash] why is Process Substitution <() so much faster ?!


file allids consists of 300,000 rows, each containing a 5-7 digit numeric id.
file newids consists of 20,000 rows of id's.

How do you explain the following timings?

time: 0.07s:
Code:
diff <(sort allids) <(sort newids)
time: 1.6s:
Code:
sort allids >allidssorted
time: 0.07s:
Code:
diff allidssorted <(sort newids)
 
Old 11-25-2010, 05:29 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Quote:
Originally Posted by hashbang#! View Post
How do you explain the following timings?
Writing to disk is slow. It might be interesting to see the timing with the temp file on a ram disk.
 
Old 11-25-2010, 05:36 PM   #3
hashbang#!
Member
 
Registered: Aug 2009
Location: soon to be independent Scotland
Distribution: Debian
Posts: 120

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by ntubski View Post
Writing to disk is slow.
Outputting to /dev/null or piping into wc -l took exactly the same time.
 
Old 11-25-2010, 05:47 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
I can't replicate your results:

Code:
~/tmp$ seq 300000 > allids
~/tmp$ seq 0 20000 2 > newids
~/tmp$ time diff <(sort newids) <(sort allids) >/dev/null

real	0m2.333s
user	0m2.260s
sys	0m0.088s
~/tmp$ time sort allids > allsorted 

real	0m2.019s
user	0m1.976s
sys	0m0.040s
~/tmp$ time diff <(sort newids) allsorted  >/dev/null

real	0m0.321s
user	0m0.288s
sys	0m0.044s
Perhaps it has something to do with the specific ids you have.
 
Old 11-26-2010, 04:19 AM   #5
hashbang#!
Member
 
Registered: Aug 2009
Location: soon to be independent Scotland
Distribution: Debian
Posts: 120

Original Poster
Rep: Reputation: 17
For my performance tests I often pipe output into tail while you were redirecting to /dev/null. I noticed that redirecting the diff output took way longer than tail.

When timing the sort, however, sorting to file, /dev/null, or tail made no difference.


Anyway, I repeated the tests and I realized that my diff output formatting makes a difference, too:

time: 0.07s piped into tail, 0.14s to /dev/null
Code:
diff --new-line-format=%L --old-line-format=  --unchanged-line-format= allidssorted <(sort newids)
time: 0.14s piped into tail, 0.2s to /dev/null
Code:
diff allidssorted <(sort newids)
And now I feel like a total idiot:

time: 0.07s piped into tail, 1.7s to /dev/null
Code:
diff <formatting> <(sort allids) <(sort newids)
I should add that there is no output because there are no newids that are not in allids.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash: functional difference between process substitution and here string with $( ) ? catkin Programming 2 03-15-2010 02:08 AM
Process Substitution not working with echo command muazfarooqaslam Linux - Newbie 1 02-04-2008 09:10 AM
Problems with Process Substitution and scp - Solaris to Linux sdduuuude Linux - Newbie 3 09-28-2007 10:47 AM
Bash Process Substitution joshholt Programming 4 10-11-2005 03:15 AM
process substitution jk3us Linux - Software 1 12-02-2004 04:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:02 PM.

Main Menu
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