![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #11 (permalink) |
| | Re: Sort files collection ? Thanks for that detailed explanation. Ill have to explore this. ADO is all new to me. |
My System Specs![]() |
| | #12 (permalink) |
| | Re: Sort files collection ? In microsoft.public.scripting.vbscript message <OEis0fhIKHA.1020@xxxxxx NGP02.phx.gbl>, Fri, 21 Aug 2009 00:33:11, mayayana <mayaXXyana@xxxxxx> posted: Quote: Quote: >> There are a lot of other sources on sorting algorithms and their benefits >> and shortcomings and formulas on how the time for sorting similar sets of >> objects varies with the number of items being sorted. Some algoriths have >> widely varying execution times for a given number if items, depending on Quote: >> they are initially ordered. Other algorithms, such as Shell sort, have >> similar execution times no matter what the initial order is. >> > Yes. I didn't do very extensive testing myself but >I did notice that. Bubble sort, especially, seems to get >slower and slower as the number of items increases. >Though with the exception of bubble sort, the methods I >was testing don't seem to matter all that much until one >gets into the hundreds of thousands or millions >of items. If a sort routine can sort, say, 10,000 items >in 150 ms, it may take 300 ms on the second run and >220 ms on the third. VBScript is just too crude to get >high accuracy in tests on that scale. But even though >there's a 200% difference in the range of results, they're >all essentially instant for most purposes. It's unlikely >that I'll ever need to sort more than a few hundred items. ![]() Read <http://en.wikipedia.org/wiki/Sorting_algorithm> and its links. -- (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links. Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036) Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036) |
My System Specs![]() |
| | #13 (permalink) |
| | Re: Sort files collection ? "mayayana" <mayaXXyana@xxxxxx> wrote in message news:ef4uv20IKHA.4708@xxxxxx Quote: > Thanks for that detailed explanation. Ill have to > explore this. ADO is all new to me. > > disconnected recordset object that can quickly convert into an array or string. For example, adding to the first example I posted earlier: ======== ' Convert recordset into an array. adoDataList.MoveFirst arrResults = adoDataList.GetRows ' Convert recordset into a semicolon delimited string. Const adClipString = 2 adoDataList.MoveFirst strResults = adoDataList.GetString(adClipString, , , ";", "<NULL>") adoDataList.Close ' Enumerate the array. intCount = 0 For Each strValue In arrResults Wscript.Echo strValue intCount = intCount + 1 Next Wscript.Echo CStr(intCount) ' Display the string. Wscript.Echo strResults ===== I haven't found a quick way to convert an array into a recordset. But, you can also apply filters to the disconnected recordset. For example: adoDataList.MoveFirst adoDataList.Filter = "Value > 'Fruit'" And finally, you can sort descending with: adoDataList.Sort = "Value DESC" -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #14 (permalink) |
| | Re: Sort files collection ? Richard Mueller [MVP] schrieb: [...] Quote: > I'll just add that there are GetRows and GetString methods of the > disconnected recordset object that can quickly convert into an array or > string. For example, adding to the first example I posted earlier: > ======== > ' Convert recordset into an array. > adoDataList.MoveFirst > arrResults = adoDataList.GetRows (first dimension) as there are columns and as many 'colums' (second dimension) as there are elements in the one dimensional array you put into the table. Quote: > ' Convert recordset into a semicolon delimited string. > Const adClipString = 2 > adoDataList.MoveFirst > strResults = adoDataList.GetString(adClipString, , , ";", "<NULL>") > adoDataList.Close (1) you want an array (back) - so strResults has to be converted (2) if you use Split on strResults, the choice if the delimiter is critical: I would consider ";" as risky (3) After aData = Split( strResults, ";" ), aData will contain one more/last empty element than the array you started with, because Split treats its second parameter as a separator. [...] |
My System Specs![]() |
| | #15 (permalink) |
| | Re: Sort files collection ? I did some testing on this. It appears that ADO has obvious advantages if one is dealing with existing recordsets. It's fairly quick and if I understand the Sort method correctly, it seems to be sortable in more than 1 column, so that names could be sorted within the same date, for instance. (?) For basic speed ADO turned out mediocre. It's plenty fast for most uses, as are all sort methods I tested except bubble sort. But it's not actually very fast. For my original sorting tests I use the following code with each sort algorithm test script, to open a dropped file and create an array: Set FSO = CreateObject("Scripting.FileSystemObject") Set TS = FSO.OpenTextFile(WScript.arguments(0), 1) s1 = TS.ReadAll TS.Close Set TS = Nothing A1 = Split(s1, " ") I then call: i = timer [SortRoutine Call here] i2 = timer i2 - i1 is the measurement. To test ADO I added the same arrray code to the beginning of your sample. It turns out that takes about 1/2 second to get an array. It doesn't seem to matter much how big the file is. I guess the FSO ops are probably most of it and the Split is probably almost instant. Starting with the array, I came up with the following: _______________________ txt file of 12,277 words ------------------ QuickSort: 441 ms ADO setup 773 ms ADO Sort 609 ms ADO Sort total 1,380 ms ________________ txt file of 73,705 words (ECMA 3 Reference 477 KB) ------------------- QuickSort: 2,860 ms ADO setup 4,179 ms ADOSort 5,269 ms ADO Sort total 9,449 ms This was just two files tested, running the test a handful of times, but it shows a trend similar to other sort methods. If only the actual sorting time is counted, ADO gets slower as the number of items gets bigger. (That seems to be true with most or all methods, except QuickSort. Or at least it's less marked with QuickSort.) My earlier tests on the 477 KB file yielded the following results: quick 2859 ms shell 5382 ms snake 17,406 ms merge 31,468 ms So ADO was comparable to ShellSort, if only the sorting is counted. And it's faster to use ADO, including setup, than it is to use SnakeSort and MergeSort. (At least with large numbers of items.) But even just the actual sorting itself is notably slower than QuickSort. Another variable I wasn't able to check: I've been using non-case-sensitive sorting. (Even though my speed tests have been for basic case-sensitive sorting.) I want an alphabetical list regardless of case. I don't see where that option comes in with ADO. I looked up the Sort method and found there seems to be only an option for ASC or DESC to pick the sort direction. There doesn't seem to be an option to choose the sort definition. My test script, using your basic code, is below: Dim FSO, TS, s1, A1, Arg, i, i2, s2, iAsc Set FSO = CreateObject("Scripting.FileSystemObject") Set TS = FSO.OpenTextFile(WScript.arguments(0), 1) s1 = TS.ReadAll TS.Close Set TS = Nothing A1 = Split(s1, " ") Dim arrAscending, adoDataList, strValue, intCount Dim dtmT1, dtmT2, dtmT3 Const adVarChar = 200 Const MaxCharacters = 255 dtmT1 = Timer() ' Setup disconnected recordset. Set adoDataList = CreateObject("ADODB.Recordset") adoDataList.Fields.Append "Value", adVarChar, MaxCharacters adoDataList.Open For Each strValue In A1 'arrRandom adoDataList.AddNew adoDataList("Value") = strValue adoDataList.Update Next dtmT2 = Timer() adoDataList.Sort = "Value" dtmT3 = Timer() ' Display sorted values. intCount = 0 adoDataList.MoveFirst Do Until adoDataList.EOF ' WScript.Echo adoDataList.Fields.Item("Value") intCount = intCount + 1 adoDataList.MoveNext Loop adoDataList.Close WScript.Echo "Number of values: " & CStr(intCount) WScript.Echo "ADO Sort setup: " & FormatNumber(dtmT2 - dtmT1, 4) WScript.Echo "ADO Sort : " & FormatNumber(dtmT3 - dtmT2, 4) WScript.Echo "ADO Sort total: " & FormatNumber(dtmT3 - dtmT1, 4) |
My System Specs![]() |
| | #16 (permalink) |
| | Re: Sort files collection ? OK... this may be more than anyone wants to know at this point, but I've done some more tests. ![]() The results are as follows: ---------------------------------------- sort test on 23 KB text file: quick 156 ms quick(NCS) 222 ms shell 226 ms snake 171 ms merge 226 ms ADO(NCS) 58/379 ms (actual sorting time / time to create ADO Recorset, transfer array, sort, and return sorted array.) bubble 15,984 ms --------------------------------- sort test on 477 KB plain text: quick 2,859 ms quick(NCS) 4,986 ms shell 5,382 ms ADO(NCS) 5,269/10,882 (actual sorting time / time to create ADO Recorset, transfer array, sort, and return sorted array.) snake 17,406 ms merge 31,468 ms --------------------------------- I don't have the .Net runtime installed, so I can't test that. NCS stands for non-case-sensitive. I rewrote an ADO script to do the whole operation of returning the sorted array. The ADO times show both numbers: actual sorting time, applicable for people working within ADO, and total time as it would be for someone using the ADO method on an array. The ADO script follows. (I didn't change the AddNew method as per ekkehard's spec. because I didn't understand that code, but I'm guessing the difference is probably negligible.) '---- drop a text file onto this script --------- Dim FSO, TS, s1, A1, Arg, i, s2, A2() Dim ADO, sWord Dim T1, T2, T3, T4 Set FSO = CreateObject("Scripting.FileSystemObject") Set TS = FSO.OpenTextFile(WScript.arguments(0), 1) s1 = TS.ReadAll TS.Close Set TS = Nothing A1 = Split(s1, " ") T1 = Timer ' Setup disconnected recordset. Set ADO = CreateObject("ADODB.Recordset") ADO.Fields.Append "Value", 200, 255 ADO.Open For i = 0 to UBound(A1) ADO.AddNew ADO("Value") = A1(i) ADO.Update Next T2 = Timer ADO.Sort = "Value" T3 = Timer '-- return the sorted array: ADO.MoveFirst A1 = ADO.GetRows ReDim A2(UBound(A1, 2)) For i = 0 to UBound(A1, 2) A2(i) = A1(0, i) Next A1 = A2 T4 = Timer ADO.Close MsgBox "ADO time required in milliseconds for " & CStr(UBound(A1)) & " values:" & vbCrLf & "ADO setup: " & CStr((T2 - T1) * 1000) & vbCrLf & "Actual Sorting: " & CStr((T3 - T2) * 1000) & vbCrLf & "Combined setup plus sort: " & CStr((T3 - T1) * 1000) & vbCrLf & "Total time to return original array sorted: " & CStr((T4 - T1) * 1000) Set ADO = Nothing |
My System Specs![]() |
| | #17 (permalink) |
| | Re: Sort files collection ? Vilius Mockûnas wrote: Quote: > How do I sort this collection by name by date and etc. > I can build sort logic of course but maybe there are easy standard ways ? > quick sort in (vb)script. He posted the result here, (vbs ng) and on Clarence Washington's website: http://cwashington.netreach.net/ A while back, Clarence stopped maintaining his website, thanks to the introduction of "a-little-bundle-of-joy" into his life (which now consumes all his spare time). And, when last seen, he was closing his site. However, nothing ever disappears from the web, and MikHar's sort routines are probably still out there in some archival site or other. cheers, jw |
My System Specs![]() |
| | #18 (permalink) |
| | Re: Sort files collection ? Il giorno Wed, 23 Sep 2009 07:49:11 -0400, mr_unreliable <kindlyReplyToNewsgroup@newsgroup> ha scritto: Quote: >Vilius Mockûnas wrote: Quote: >> How do I sort this collection by name by date and etc. >> I can build sort logic of course but maybe there are easy standard ways ? >> >Several years ago, Mike Harris wrote a Shell Sort and a >quick sort in (vb)script. He posted the result here, >(vbs ng) and on Clarence Washington's website: > > http://cwashington.netreach.net/ > >A while back, Clarence stopped maintaining his website, >thanks to the introduction of "a-little-bundle-of-joy" >into his life (which now consumes all his spare time). >And, when last seen, he was closing his site. However, >nothing ever disappears from the web, and MikHar's sort >routines are probably still out there in some archival >site or other. www.jsware.net A list of files can be sorted using the switches of the dir command and redirecting the output. Or shell a sort command on the list (sort by name only). -- Giovanni Cenati (Bergamo, Italy) Write to "Reventlov" at katamail com http://digilander.libero.it/Cenati (Esempi e programmi in VbScript) -- |
My System Specs![]() |
| | #19 (permalink) |
| Vista Home Premium 32 | Re: Sort files collection ? I know this is a bit off thread, as this is just in normal Windows usage, but I use the current ISO date/time string (yy;MM;ddthh;mm;ss) as a unique identifier, pasting it before the file name, for any files I want to keep in the order I filed them or received them (usually work related). |
My System Specs![]() |
| | #20 (permalink) |
| | Re: Sort files collection ? In microsoft.public.scripting.vbscript message <22f6f6d408818bb58f99a98c 2b24aa78@newsgroup-gateway.com>, Sun, 1 Nov 2009 20:36:45, tonyb <guest@newsgroup-email.com> posted: Quote: > >I know this is a bit off thread, as this is just in normal Windows >usage, but I use the current ISO date/time string (yy;MM;ddthh;mm;ss) as >a unique identifier, pasting it before the file name, for any files I >want to keep in the order I filed them or received them (usually work >related). semicolon as separator. While the first two digits of the year will not change soon, they do serve to indicate that the field order is not MDY of DMY, and is probably YMD. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05. Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Collection of Batch files for everyone to use! | General Discussion | |||
| Sort by date? And Folder missing files | General Discussion | |||
| Re: Can I sort within a sort, in folder view (eg., Name, Date) | Live Mail | |||
| Sort by name doesnt sort correctly in my opinion | Vista file management | |||
| Disabling auto alphabetical order sort in start / program files | Vista General | |||