• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: minimum function?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: minimum function?


  • Subject: Re: minimum function?
  • From: jj <email@hidden>
  • Date: Wed, 06 Apr 2005 11:38:18 +0200

> The shell will deliver in less than one second what the cleanest AS script
> will take at least 20 seconds to do:

Hmmm... In the exposed example, the shell seems a very slow option. Perhaps
"sort" is fast, but not "do shell script". I've tested it against Satimage's
"statlist" and plain-vanilla-AS (using acelleration techniques described
here several times). Try this code (it uses Smile's "chrono" command, but
may be replaced with GetMilliSec or Jon's Commands' "the ticks"):

############################
--> create 10000-items list
set nList to {}
repeat 10000 times
    set end of nList to random number from 1 to 99999999
end repeat

chrono
repeat 20 times
    sortMin(nList)
end repeat

set sortMinSpeed to chrono

repeat 20 times
    minimum of (statlist nList)
end repeat

set statlistSpeed to chrono

repeat 20 times
    getMin(nList)
end repeat

set getMinSpeed to chrono

{sortMinSpeed, statlistSpeed, getMinSpeed}
--> {13.853702, 4.746942, 4.125726}

on sortMin(nList)
    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ASCII character 10
    set sList to nList as string
    set n to do shell script "echo " & quoted form of sList & " | sort -n"
    set AppleScript's text item delimiters to oldDelims
    set x to paragraph 1 of n
    return x
end sortMin

to getMin(x)
    script a
        property theList : x
    end script

    set min to a's theList's item 1

    repeat with i from 2 to count x
        if a's theList's item i < min then set min to a's theList's item i
    end repeat

    return min
end getMin
############################

I didn't tried with a really-long list, but I think 10000 items is good
enough for this test, and I don't think a 1 million items list is
handle-able with AS (I think it could be done only using a combo of
Satimage's "statlist" and "read binary"/"write binary").


jj

--
http://www.macscripter.net/
http://www.osaxen.com/


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: minimum function? (From: Martin Orpen <email@hidden>)

  • Prev by Date: Re: matching strings with accented characters
  • Next by Date: RE: merge pdfs
  • Previous by thread: Re: minimum function?
  • Next by thread: Re: minimum function?
  • Index(es):
    • Date
    • Thread