Re: Getting time components of date
Re: Getting time components of date
- Subject: Re: Getting time components of date
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 23 Dec 2003 00:52:33 -0800
But did you test it against Arthur's script?
The reason why some pure AppleScripts can be faster than a 'do shell
script', no matter how fast the actual shell script is in Terminal, is that
'do shell script' is a scripting addition and, as such, has an overhead when
run in AppleScript. AppleScript first searches the 'current application' for
all terms, then every scripting addition until it hits 'do shell script',
then has to hook into sh, and so on. If you take even a cursory look at
Arthur's handler you'll see that it almost all consists of 'else if'
branchings, so only a tiny portion of it actually runs.
I haven't tested it either, but I'm sure someone will.
--
Paul Berkowitz
>
From: Graff <email@hidden>
>
Date: Tue, 23 Dec 2003 03:23:02 -0500
>
To: Applescript Users <email@hidden>
>
Subject: Re: Getting time components of date
>
>
Well if we are talking speed, you probably won't get faster than this
>
unless you like to code in machine code:
>
-------------
>
#include <stdio.h>
>
#include <time.h>
>
>
#define MAX_SIZE 32
>
#define FORMAT_STRING "%Y-%m-%d %H:%M:%S\n"
>
>
int main (int argc, const char * argv[])
>
{
>
time_t *currTime;
>
struct tm *currLocalTime;
>
char outputString[MAX_SIZE];
>
>
time(currTime);
>
currLocalTime = localtime(currTime);
>
if (currLocalTime != NULL)
>
{
>
strftime(outputString, MAX_SIZE - 1, FORMAT_STRING, currLocalTime);
>
}
>
>
printf("%s", outputString);
>
return 0;
>
}
>
-------------
>
>
Put it into a text editor, save it on your desktop as a plain text file
>
with unix line endings and the name "timestring.c". Go into the
>
terminal and type:
>
cc ~/Desktop/timestring.c -o ~/Desktop/timestring
>
>
Boom, your very own command-line tool. Run it in AppleScript like this:
>
set theTime to do shell script "~/Desktop/timestring"
>
>
Don't mind me, I'm feeling a little cheeky. ;-)
>
>
- Ken
>
>
On Dec 23, 2003, at 12:02 AM, Christopher Stone wrote:
>
>
> At 7:59 AM -0500 12/22/03, Chris Garaffa wrote:
>
>> While working to convert an AppleScript date to a MySQL DATETIME date
>
>> (yyyy-mm-dd hh:mm:ss) I ran into a small problem. While AppleScript
>
>> supports things like:
>
> ______________________________________________________________________
>
>
>
> Here's Arthur Knapp's handler. On my system it creates the requisite
>
> date string in ~ 0.0024 seconds.
>
>
>
> As opposed to ~ 0.01 seconds for the shell script.
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.