• 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: [applescript] Slow code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [applescript] Slow code


  • Subject: Re: [applescript] Slow code
  • From: Brian Christmas <email@hidden>
  • Date: Tue, 12 Sep 2017 19:32:54 +1000

Of interest, it appears the random number generation is the bottleneck.

I stripped and simplified the code to the first example below, and it averages
11.5 seconds, a drop of about 5 seconds. Using brackets ie (characters 1
through 6 of temp)  sped things up, (and adding a ‘my’ in front of the number
formatter caller of my old code added 2 seconds.)

I then modified the code as per the second example, and the time average did
not alter.

Any way to speed up the generation of a random number, please?

It’s also remarkable how many seconds each time can vary by! + - 2 seconds
either side of a rough average.

Regards

Santa


use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions
set l to ""
set f1 to 19480822
set f2 to 19471206
random number 1.0E+11 to 9.99999999999E+11 with seed my fixIt()
repeat with x from 1 to 10000
        set f1 to f1 + (random number from 10 to 100) # NEED THESE as they’re
always different, whereas the last one MIGHT be a duplicate occasionally
        set f2 to f2 + (random number from 10 to 100)
        tell current application's class "NSNumber" to set theNSNumber to
(random number from 1.00000000001E+11 to 9.99999999999E+11)
        tell current application's class "NSNumberFormatter" to set temp to
(localizedStringFromNumber_numberStyle_(theNSNumber, current application's
NSNumberFormatterNoStyle)) as string
        set l to (l & f1 as text) & "-" & f2 & "-" & (characters 1 through 6 of
temp) & "-" & (characters 7 through 12 of temp) & return
end repeat

 on fixIt()
        # Allready posted altered version
        return x
end fixIt



use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions
set l to ""
set f1 to 19480822
set f2 to 19471206
random number 1.0E+11 to 9.99999999999E+11 with seed my fixIt()
repeat with x from 1 to 10000
        set f1 to f1 + (random number from 10 to 100)
        set f2 to f2 + (random number from 10 to 100)
        set temp to (random number from 100001 to 999999)
        set temp2 to (random number from 100001 to 999999)
        set l to (l & f1 as text) & "-" & f2 & "-" & temp & "-" & temp2 & return
end repeat

on fixIt()
        # Allready posted altered version
        return x
end fixIt



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Slow code (From: Brian Christmas <email@hidden>)
 >Re: Slow code (From: Takaaki Naganoya <email@hidden>)

  • Prev by Date: Re: [applescript] Slow code
  • Next by Date: Re: Saving an encrypted PDF in Word 2016
  • Previous by thread: Re: [applescript] Slow code
  • Next by thread: Re: [applescript] Slow code
  • Index(es):
    • Date
    • Thread