<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sort in awk is very slow in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720832#M721701</link>
    <description>&lt;BR /&gt;perl is an option, or even faster hardware.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
    <pubDate>Thu, 09 May 2002 17:56:21 GMT</pubDate>
    <dc:creator>harry d brown jr</dc:creator>
    <dc:date>2002-05-09T17:56:21Z</dc:date>
    <item>
      <title>Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720831#M721700</link>
      <description>Hello Gang,&lt;BR /&gt;&lt;BR /&gt;I seem to have coded myself into a corner. I am working on a fairly complex set of financial reports written mainly in awk. The reports work but take a very long time to complete. I have found that my main problem is the sort. The sort example I use was taken from the O'reilly Book "Sed &amp;amp; Awk" on page 222. It is very compact and works well when the array is small but when processing about 5000 accounts can take several minutes to finish. My data is actually accumulated in a number of parallel arrays. I also have an array which looks like this:&lt;BR /&gt;202-456-4490 908&lt;BR /&gt;102-412-6512 134&lt;BR /&gt;000-000-0000 0&lt;BR /&gt;000-000-0001 1&lt;BR /&gt;&lt;BR /&gt;The first field is the account number and the second field is the&lt;BR /&gt;index in the original arrays. I then sort this array and output the original parallel array values using the second field of this sorted array to access the data. The reports now print in account number order just as they should. My only problem is the speed of the sort. I am thinking about writing the data to a file and then calling the sort program but maybe someone has a better idea.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance, Neil&lt;BR /&gt;</description>
      <pubDate>Thu, 09 May 2002 17:52:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720831#M721700</guid>
      <dc:creator>Neil Edwards</dc:creator>
      <dc:date>2002-05-09T17:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720832#M721701</link>
      <description>&lt;BR /&gt;perl is an option, or even faster hardware.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Thu, 09 May 2002 17:56:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720832#M721701</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-05-09T17:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720833#M721702</link>
      <description>Try converting your awk script to perl:&lt;BR /&gt;&lt;BR /&gt;a2p &lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Thu, 09 May 2002 18:03:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720833#M721702</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-05-09T18:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720834#M721703</link>
      <description>Hi Neil:&lt;BR /&gt;&lt;BR /&gt;I had to pull out my copy of 'Sed &amp;amp; Awk' to see what you were talking about but as soon as I did I saw what your problem is. This is a classic 'bubble sort' and its performances degrades with the square of the number of elements. &lt;BR /&gt;&lt;BR /&gt;Before I give you a good answer, I suppose I should point out that all that parallel array nonsense (excuse me - code) could have been avoided with the use of perl (specifically the Class:Struct module) which could have kept all your data related to one account in a nice box (a struct/record).&lt;BR /&gt;&lt;BR /&gt;The good news is that in my awk code library, I have a sort function that will do the trick and should do in at most a few seconds what takes your bubblesort minutes. (It does assume that your arrays are numeric indexed rather than associative and the lowest index is 1).&lt;BR /&gt;&lt;BR /&gt;use it like this:&lt;BR /&gt;&lt;BR /&gt;qsort(my_array,1,count)&lt;BR /&gt;Arg 1 = the array to sort&lt;BR /&gt;Arg 2 = 1 (because this is a recursive function it needs an array lower bounds; should always be 1)&lt;BR /&gt;Arg 3 = number of elements in the array&lt;BR /&gt;&lt;BR /&gt;This should fix you, Clay&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 09 May 2002 18:09:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720834#M721703</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-05-09T18:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720835#M721704</link>
      <description>Thanks for the quick responses!&lt;BR /&gt;&lt;BR /&gt;I've tried to learn Perl but I seem to get bogged down everytime I try. Clay, I put in your sort function and sorts that were taking 15 minutes are now done in 1 or 2 seconds!!! I can only say wow!!! I am truly amazed because your sort is only a few lines longer than mine. My users are going to be impressed with 'my' work.&lt;BR /&gt;&lt;BR /&gt;Thanks again, Neil</description>
      <pubDate>Thu, 09 May 2002 18:53:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720835#M721704</guid>
      <dc:creator>Neil Edwards</dc:creator>
      <dc:date>2002-05-09T18:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720836#M721705</link>
      <description>Hi again Neil:&lt;BR /&gt;&lt;BR /&gt;I'm glad you liked the sort function. The fundamental problem with your sort is that the exchange interval (1) is so small that repeated passes are required to sort the data.&lt;BR /&gt;I actually have a better function that combines the best features of quicksort and bubblesort by switching to bubblesort when the array boundaries are small. Bubblesort excels in this environment. Since you are already in the 1-2 second range and seem happy, I don't think I will bother.&lt;BR /&gt;</description>
      <pubDate>Thu, 09 May 2002 19:00:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720836#M721705</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-05-09T19:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720837#M721706</link>
      <description>Hi Clay,&lt;BR /&gt;&lt;BR /&gt;I just saw your last post. Would you mind posting your better sort function? I would really like to squeeze all the speed out of this program that I can.&lt;BR /&gt;&lt;BR /&gt;TIA, Neil</description>
      <pubDate>Fri, 10 May 2002 14:29:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720837#M721706</guid>
      <dc:creator>Neil Edwards</dc:creator>
      <dc:date>2002-05-10T14:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720838#M721707</link>
      <description>Okay, but I suspect the improvements are going to be small. Use it like this:&lt;BR /&gt;&lt;BR /&gt;bqsort(my_array,1,count,6)&lt;BR /&gt;&lt;BR /&gt;The 4th argument is the 'bubblepoint' and whenever a quicksort partition size falls to this value, bubblesort is used instead.&lt;BR /&gt;&lt;BR /&gt;The 'bubblepoint' should probably be kept in the range of 4 to 10 - 6 is an all-around good value for the vast majority of datasets.&lt;BR /&gt;&lt;BR /&gt;Clay&lt;BR /&gt;</description>
      <pubDate>Fri, 10 May 2002 15:06:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720838#M721707</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-05-10T15:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720839#M721708</link>
      <description>Oops ....&lt;BR /&gt;&lt;BR /&gt;I'm am idiot. That should be:&lt;BR /&gt;qbsort(my_array,1,count,6)&lt;BR /&gt;&lt;BR /&gt;Clay&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 10 May 2002 15:22:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720839#M721708</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-05-10T15:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sort in awk is very slow</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720840#M721709</link>
      <description>Thanks again Clay. That speeded up the sort by maybe 10%.&lt;BR /&gt;&lt;BR /&gt;Neil</description>
      <pubDate>Fri, 10 May 2002 17:05:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sort-in-awk-is-very-slow/m-p/2720840#M721709</guid>
      <dc:creator>Neil Edwards</dc:creator>
      <dc:date>2002-05-10T17:05:31Z</dc:date>
    </item>
  </channel>
</rss>

