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-20-2009, 04:34 AM   #16
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244

Quote:
Originally Posted by H_TeXMeX_H View Post
From my tests it's about 4x faster than awk,
hmm, because your program is smaller than (m)awk??
 
Old 11-20-2009, 04:50 AM   #17
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Ok, I got mawk and here's my test results:

Code:
bash-3.1$ time mawk 'NR >= 300 && NR <= 1500' out > tt

real	0m0.003s
user	0m0.001s
sys	0m0.003s
bash-3.1$ time mm 300 1500 out > ttttt

real	0m0.001s
user	0m0.000s
sys	0m0.001s
bash-3.1$ time awk 'NR >= 300 && NR <= 1500' out > tt

real	0m0.004s
user	0m0.002s
sys	0m0.001s
bash-3.1$ time sed -n '300,1500 p' out > tttt

real	0m0.003s
user	0m0.002s
sys	0m0.001s
 
Old 11-20-2009, 05:02 AM   #18
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by H_TeXMeX_H View Post
Ok, I got mawk and here's my test results:
Code:
bash-3.1$ time awk 'NR >= 300 && NR <= 1500' out > tt
change the awk code to
Code:
awk 'NR>=300{print}NR==1500{exit}' out
Same as sed.
Code:
sed -n '300,1500{p;q}' out
i think you will see big difference.

Last edited by ghostdog74; 11-20-2009 at 05:03 AM.
 
Old 11-20-2009, 05:20 AM   #19
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Well, you're right about sed, it's just as fast as the C program:

Code:
bash-3.1$ time sed -n '300,1500{p;q}' out > ttt

real	0m0.001s
user	0m0.001s
sys	0m0.000s
bash-3.1$ time sed -n '300,1500{p;q}' out > ttt

real	0m0.001s
user	0m0.000s
sys	0m0.001s
But awk and mawk still don't do any better:

Code:
bash-3.1$ time awk 'NR>=300{print}NR==1500{exit}' out > tt

real	0m0.004s
user	0m0.001s
sys	0m0.003s
bash-3.1$ time mawk 'NR>=300{print}NR==1500{exit}' out > tt

real	0m0.003s
user	0m0.000s
sys	0m0.003s
Strange ...

Well, at least you can use sed and don't need the program I posted.
 
Old 11-20-2009, 11:37 AM   #20
Rusty2727
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Very constructive comments!

In the end I also found that 'sed' was the simplest and fastest way to go.

I actually also used 'tail' to remove data from the input as and when it wasn't needed anymore.

This allowed the input to shrink as the while loop progressed making it progressively quicker with each iteration.

Still a bit slow though for my requirement.

Many thanks everybody for all your input.

Have a good weekend!!!
 
Old 11-20-2009, 01:21 PM   #21
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
In that case I would try to put it all in a C program if you can.
 
Old 11-22-2009, 03:22 PM   #22
cyent
Member
 
Registered: Aug 2001
Location: ChristChurch New Zealand
Distribution: Ubuntu
Posts: 398

Rep: Reputation: 87
Quote:
Originally Posted by H_TeXMeX_H View Post
oops, sorry, I was tired, here's the correct one
Ok, that's better!

Quote:
run 'strip --strip-unneeded' on it)
Does that really make any difference to the speed? I thought it just stripped out things like debug symbols. ie. Took up less disk space, but didn't make it faster.
 
Old 11-23-2009, 03:37 AM   #23
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by cyent View Post
Ok, that's better!



Does that really make any difference to the speed? I thought it just stripped out things like debug symbols. ie. Took up less disk space, but didn't make it faster.
well, maybe just a bit faster, because it takes less time to load it into RAM and it can skip over the unneeded symbols ... I'm not sure, but it does at least save space.
 
  


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
ext3 optimisation STARHARVEST Linux - General 3 03-22-2008 10:24 PM
Performance optimisation on the notebooks SuSE_Lamer Debian 4 05-02-2006 12:57 PM
My own server - bandwidth use optimisation eomerek Linux - Networking 3 02-12-2006 04:20 PM
-march optimisation for kernel BenPope Linux - General 2 09-03-2003 11:36 AM
Compiling (GCC) - Optimisation anonE9 Programming 5 03-15-2003 08:20 PM

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

All times are GMT -5. The time now is 04:36 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