Now, I will search for fastest way to get base name of file. (in microseconds).
To get such results, I will use -1000000 multiplier. I will use 100 repetitions and will run test 5 times x 100 repetitions.
The file on my disk is this:
set theFile to "/Users/123/Library/Scripts/Get the Selection in app.scpt"
The 1st way will be the text item delimiters way:
set TID to text item delimiters
set text item delimiters to {"/"}
set n to last text item of theFile
set text item delimiters to TID
--> 8,9,9,10,9 --> about 9 microseconds
The 2nd way will be the do shell script way:
set n to do shell script "basename " & quoted form of theFile
--> 21992, 20921, 22719, 22846, 25280 --> about 23000 microseconds
The 3rd way will be the System Events way:
tell application "System Events" to set n to name of disk item theFile
--> 7749, 7798, 7806, 8404, 8136 --> about 8000 microseconds
Next will be the info for way:
set n to name of (info for (POSIX file theFile as alias))
--> 6130, 4558, 4259, 2498, 2500 --> about 4000 microseconds
And last but not least the ASObjC way:
set theURL to current application's |NSURL|'s fileURLWithPath:theFile
set n to theURL's lastPathComponent() as text
--> 209, 194, 183, 200, 219 --> about 200 microseconds
Note: when I put 1st line of this code offside the repeat loop, 2nd line code still takes 90 microseconds.
All these tests was performed with Nigel Garvey’s timing wrapper