Re: NSFileManager's odd behavior
Re: NSFileManager's odd behavior
- Subject: Re: NSFileManager's odd behavior
- From: Takaaki Naganoya <email@hidden>
- Date: Thu, 23 Jul 2015 17:39:27 +0900
2015/07/23 8:09、Shane Stanley <email@hidden> のメール:
> On 23 Jul 2015, at 12:10 am, Takaaki Naganoya <email@hidden> wrote:
>>
>> By the way…there is other odd behavior for me. It is the *speed*.
>> I thought AS2 is faster than AS1. But in fact, AS1 is about two times faster than AS2.
>
> Like Axel, I get similar speeds. I wonder if the difference can be explained by the folders already being there for one script, and not the other -- that makes quite a difference.
>
> You can also change this:
>
>> set aDirText to "Desktop/test/" & (i as string)
>>
>> set aDirStr to (current application's NSString's stringWithString:aDirText)
>> set dirPath to (homeDir's stringByAppendingPathComponent:aDirStr)
>
> To this:
>
> set aDirText to "Desktop/test/" & (i as string)
> set dirPath to (homeDir's stringByAppendingPathComponent: aDirText)
>
> in the second script. It may not seem much, but it makes quite a difference here.
Hi Shane, your advice changed the results (many thanks).
Now, AS2+ is faster than AS1 as I expected.
AS1: 5.814414978027 sec.
AS2+: 4.124059021473 sec
(MacBook Pro Retina 2012, Core i7 2.6GHz, OS X 10.10.5)
I was an computer magazine editor. So, I know that file/folder deletion requires special care :-).
My MacBook Pro is a little old one, but it has 4-core & 8-threads.
Many Core processor system may change the behavior.
<AS1>
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set a1Dat to current application's NSDate's timeIntervalSinceReferenceDate()
repeat with i from 1 to 10000
set aDirStr to "Desktop/test/" & (i as string)
set aRes to makeDirUnderHome(aDirStr) of me
end repeat
set b1Dat to current application's NSDate's timeIntervalSinceReferenceDate()
set c1Dat to b1Dat - a1Dat
--> 5.814414978027 (MacBook Pro Retina 2012, Core i7 2.6GHz)
on makeDirUnderHome(dirStr)
set homeDir to current application's NSHomeDirectory()
set dirPath to homeDir's stringByAppendingPathComponent:dirStr
set fileManager to current application's NSFileManager's defaultManager()
--Sample with continuation mark (¬) , similar to Objective-C format
set aRes to fileManager's createDirectoryAtPath:dirPath ¬
withIntermediateDirectories:true ¬
attributes:(missing value) ¬
|error|:(reference)
--Sample without continuation mark (¬)
--set aRes to fileManager's createDirectoryAtPath:dirPath withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
copy aRes to {aFlag, aError}
return aFlag as boolean
end makeDirUnderHome
</AS1>
<AS2+>
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set a1Dat to current application's NSDate's timeIntervalSinceReferenceDate()
set homeDir to current application's NSHomeDirectory()
set fileManager to current application's NSFileManager's defaultManager()
repeat with i from 1 to 10000
set aDirText to "Desktop/test/" & (i as string)
set dirPath to (homeDir's stringByAppendingPathComponent:aDirText)
set aRes to (fileManager's createDirectoryAtPath:dirPath withIntermediateDirectories:true attributes:(missing value) |error|:(reference))
end repeat
set b1Dat to current application's NSDate's timeIntervalSinceReferenceDate()
set c1Dat to b1Dat - a1Dat
--> 4.124059021473 (MacBook Pro Retina 2012, Core i7 2.6GHz)
</AS2+>
--
Takaaki Naganoya
email@hidden
http://piyocast.com/as/
_______________________________________________
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