9

Is there a difference in performance between running a Python script in the Python window versus running it as a Python script tool from the toolbox in ArcGIS Desktop 10.0?

Sometimes I need to use ArcPy and have ArcGIS running. In my recent experience I can run the same script via toolbox and in the python window and the toolbox seems to be a bit faster.

  • When using stand alone scripts: you don't have to open Arcmap, thus saving you time and resources (CPU and memory). I can't afford a decent computer at the moment. – gm70560 May 20 '13 at 19:50
  • The toolbox is also not able to touch the CURRENT map document. You have to point to a mxd to do anything with a specific map in a tool, wheras you can use arcpy.mapping.MapDocument("CURRENT") in the python window. – eseglem May 20 '13 at 20:10
  • 3
    @eseglem, you should definitely be able to use the CURRENT keyword to access the current map document in a script tool, as long as it is being run in-process. – blah238 May 20 '13 at 20:25
  • 1
    @gm70560 When you run a standalone script you are having to create a kind of Arcmap instance, which takes time. Within the python window that is already started. – Matthew Snape May 20 '13 at 21:56
  • 2
    import arcpy will take a long time as a standalone script (or part of a toolbox), whereas within ArcMap it is already part of the namespace of the python window. – Michael Markieta May 21 '13 at 0:35
5

Both Michael Markieta and gm70560 are correct. If you are running running large geoprocessing tasks, I would definitely do it via a stand-alone python script, preferably launched from the command line and not an IDE. For this sort of task, the overhead of importing ArcPy is well worth it.

However, a small task, especially one which requires user input, is usually faster and more convenient in ArcMap - unless you have to open ArcMap specifically for the purpose in which case you have the overhead of of starting ArcMap itself plus some downtime to connect to all your databases referenced in the MXD (which if they are over a slow network connection can be tedious).

Likewise, batch processing even small tasks is, in my opinion, better done in a stand-alone Python script than via a toolbox in ArcMap because you take that import hit only once and don't have the ArcMap overhead.

Having done a lot of automated geoprocessing via Python scripts, I would default to running them as stand alone processes because I like the additional speed and flexibility. Most tasks which run faster in the toolbox are usually small enough that I would have knocked them up in ModelBuilder without bothering to write any code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.