What is your "import arcpy" overhead?

1635
17
03-05-2020 12:02 PM
MattWilkie1
Occasional Contributor II

I'm curious, how long does it take in your machine(s) for your scripts to get ready to start working?

Put something like this at the beginning of some scripts and share the results.

from timeit import default_timer as timer
start = timer()
from datetime import datetime, timedelta
print('=== {}'.format(datetime.now()))

start_arc = timer()
import arcpy
done_arc = timer() - start_arc

print('--- import arcpy overhead: {}'.format(timedelta(seconds=done_arc)))

#import os, math, ...
#carry on with your stuff

elapsed_time = timedelta(seconds=timer() - start)
    # get timer seconds and convert to hh:mm:ss
print('=== Total Elapsed Time: {}'.format(elapsed_time))‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

After about a week and perhaps 30 trials in various circumstances the fastest time I've ever seen is 7.8 seconds, the slowest is 10.5, and the median is ~8.5.

(updated code to run in py 2.7 and 3.6+)

Tags (2)
17 Replies
JoshuaBixby
MVP Esteemed Contributor

That is interesting.  Are you sure you aren't sitting in an Esri office somewhere...

0 Kudos
DanPatterson_Retired
MVP Emeritus

Cold start (both computer and operator)

Named User license

=== 2020-03-06 18:15:53.214205
--- import arcpy overhead: 0:00:07.948694
=== Total Elapsed Time: 0:00:07.949882

Spyder, kernel restart

=== 2020-03-06 18:17:48.751537
--- import arcpy overhead: 0:00:07.402486
=== Total Elapsed Time: 0:00:07.403328

Sadly, just about everything in the stream imports arcpy at some point

but if you just import what you need, you keep the namespace uncluttered.

Also, import python modules and other 3rd party modules "before" you import arcpy

My favorite... just run it again with no restart

=== 2020-03-06 18:19:29.711990
--- import arcpy overhead: 0:00:00.000067
=== Total Elapsed Time: 0:00:00.000738

0 Kudos
MattWilkie1
Occasional Contributor II

I updated the script so it outputs as a table, for easier comparison:

What is your "import arcpy" overhead? · GitHub 

Does anyone know how to add what the license type and status is?  (are we currently in mode "Single Use, Concurrent, Concurrent but Borrowed, AGOL, AGOL but Offline" etc.?)

And what about automatically appending to a public report Gist or similar?

0 Kudos
DanPatterson_Retired
MVP Emeritus

They may be in the arcgis module

Do you want the additions there? or here?

0 Kudos
MattWilkie1
Occasional Contributor II

There would be easier to track I think (and thanks in advance!)

0 Kudos
MattAdams
New Contributor II

Here are my results on Windows 10 running ArcGIS Pro 2.5:

=== 2020-03-09 16:22:25.363385
--- import arcpy overhead: 0:00:03.624114
=== Total Elapsed Time: 0:00:03.646515

0 Kudos
CarlosSousaFerreira
New Contributor III

Here are my results running from command line on Windows 10 Enterprise (64 bit); RAM: 8GB; Processor: Intel Core i#-6100 CPU @ 3.70GHz; ArcGIS Desktop 10.5.1 - License: Advanced (ArcInfo) Single Use

=== 2020-03-10 12:05:39.100000
--- import arcpy overhead: 0:00:02.663260
=== Total Elapsed Time: 0:00:02.666598

Surprised to see how it is a good result comparing with the other answers

0 Kudos
by Anonymous User
Not applicable

Desktop 10.5 - concurrent license; Win 10 Enterprise x64, 64GB RAM; test through PyCharm

First run: 9.35 seconds 

Second run: 3.86 seconds

Pro 2.4 - AGOL license; test through PyCharm

First run: 5.8 seconds

Second run: 4.3 seconds

0 Kudos