Joel:
> Someone who's already been benchmarking might try comparing this
>  with what's already been proposed, using the data from your web
>  site.

Done that!!

Timings I get are:

47.29  --  Sunanda's parse in the Sort 
 8.62  --  Gregg's parse before the sort
 2.25  -- Joel's bridge sort

You are today's lucky benchmark winner!!!

Though I'm not sure I'd recommend your method to Louis unless he's absolutely 
certain that that first field is:
 a) always an integer -- not a character string or a decimal
 b) never has a plus sign
 c) is never zero
 d) is never negative
 e) is never greater than 999
 f) always has leading zeroes to make it 3 digits long
 g) is always in base 10 or below

Those sorts of assumptions are hostages to fortune, and are only worth it if 
the performance gain is utterly unliveable without.

I've copied the benchmark code I used below for any one who wants to try it 
on their machine.  You will need a copy of Louis' data.

I've tried to make the benchmarks fair:
-- they all start with the unsorted data in Data 
-- and end with the sorted data in Sorted-data.
-- None of the times include reading Data from disk
-- or writing Sorted-data back.

But they could all be tuned:
-- preallocating blocks
-- or arguing that creating Sorted-data is unnecessary for a given algorithm.

I'm kinda interested in how these perform on machines with far less memory 
that Joel's or mine. 

Thanks for an interesting problem, Louis.  It's saved me from doing the 
crossword today <g>

Sunanda

rebol []

report-item: func [what [string!] /start /end /local times] [
 times: []
    if start [
        clear times
        append times now/time/precise
        print ["Started" what times/1]
        ]
   
   if end [
       append times now/time/precise   
       print ["  Ended" what times/2 " elapsed: " times/2 - times/1 ]
       ]
]



report-item/start "reading data"
data: read/lines %louis-data.txt
;; local copy of http://www.pusatberita.com/test.txt

report-item/end "reading data"



;; Sunanda -- Parse every sort compare
;; -----------------------------------

unset 'sorted-data
recycle

report-item/start "parse/stable"

sort/compare  sorted-data: copy data func [a b /local  a-key b-key ] [
    a-key: second parse/all a " "
    b-key: second parse/all b " "
    either a-key < b-key [return -1]
    [either a-key = b-key [return 0] [return +1]]
]

report-item/end "parse/stable"


write/lines %sorted-data-parse.txt sorted-data


;; Scott -- pre-parsed before sort
;; -------------------------------

unset 'sorted-data
recycle

report-item/start "pre-parsed/stable"
data-blk: copy []
foreach datum data [
    append data-blk second parse/all datum " "
    append data-blk datum
]


sort/skip data-blk 2

sorted-data: copy []
foreach [key value] data-blk [
    append sorted-data value
    ]
report-item/end "pre-parsed/stable"

write %sorted-data-pre-parsed.txt ""
foreach value sorted-data [
    write/lines/append %sorted-data-pre-parsed.txt value
]




;; Joel -- bridge sort
;; -------------------

unset 'sorted-data
recycle

report-item/start "bridge sort"
buffer: []

foreach item data [
    nr: to-integer copy/part next item 3
    while [
        nr > length? buffer
    ][
        insert/only tail buffer copy []
    ]
    append buffer/:nr item
]

sorted-data: copy []

foreach group buffer [
    foreach line group [
        append sorted-data line
    ]
]

report-item/end "bridge sort"


write %sorted-data-bridge.txt ""
foreach value sorted-data [
    write/lines/append %sorted-data-bridge.txt value
]

unset 'sorted-data
recycle


;; Verify sort results
;; ===================

report-item/start "verifying results are the same"
 parsed-file: read %sorted-data-parse.txt 
 pre-parsed-file: read %sorted-data-pre-parsed.txt
 bridge-file: read %sorted-data-bridge.txt
 
 either all [parsed-file = pre-parsed-file
             parsed-file = bridge-file
        ]
   [print "got same results"]
   [print "bad code in there somewhere"]
  
report-item/end "verifying results are the same"

print "done"
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to