<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is the Data Access module faster at counting features than MakeTableView + GetCou in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197814#M15160</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For those interested,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here are my results with a feature class that contains 1 million point features generated randomly in ArcMap:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;"""Method 1""" import time import arcpy&amp;nbsp; arcpy.env.workspace = "C:\CountTest.gdb"&amp;nbsp; StartTime = time.clock()&amp;nbsp; # Grab the time after importing the arcpy module (heavy), and setting workspace.&amp;nbsp; with arcpy.da.SearchCursor("RandomPoints", ["OBJECTID"]) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = {row[0] for row in cursor}&amp;nbsp; count = 0 for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1&amp;nbsp; EndTime = time.clock()&amp;nbsp; print "Finished in %s seconds" % (EndTime - StartTime) print count&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 6.75371938368 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; =============================== RESTART =============================== &amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 6.8498145457 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; =============================== RESTART =============================== &amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 6.8776609853 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;"""Method 2""" import time import arcpy&amp;nbsp; arcpy.env.workspace = "C:\CountTest.gdb"&amp;nbsp; StartTime = time.clock() # Grab the time after importing the arcpy module (heavy), and setting workspace.&amp;nbsp; arcpy.MakeTableView_management("RandomPoints", "myTableView") count = int(arcpy.GetCount_management("myTableView").getOutput(0))&amp;nbsp; EndTime = time.clock()&amp;nbsp; print "Finished in %s seconds" % (EndTime - StartTime) print "%s features" % count&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 1.68345616753 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; =============================== RESTART =============================== &amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 1.64100628447 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; =============================== RESTART =============================== &amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 1.65225749949 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 23 Jul 2012 17:31:49 GMT</pubDate>
    <dc:creator>MichaelMarkieta</dc:creator>
    <dc:date>2012-07-23T17:31:49Z</dc:date>
    <item>
      <title>Is the Data Access module faster at counting features than MakeTableView + GetCount</title>
      <link>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197813#M15159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Given the functions in my python application, I would rather use the new data access module and Search Cursors to access my data and iterate through an object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Planning for the future, which method would produce quicker results when scaled upwards (more features)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor("myFeature", ["OBJECTID"]) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = sorted({row[0] for row in cursor})&amp;nbsp; count = 0 for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeTableView_management("myFeature", "myTableView") count = int(arcpy.GetCount_management("myTableView").getOutput(0))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2012 18:14:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197813#M15159</guid>
      <dc:creator>MichaelMarkieta</dc:creator>
      <dc:date>2012-07-13T18:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Is the Data Access module faster at counting features than MakeTableView + GetCou</title>
      <link>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197814#M15160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For those interested,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here are my results with a feature class that contains 1 million point features generated randomly in ArcMap:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;"""Method 1""" import time import arcpy&amp;nbsp; arcpy.env.workspace = "C:\CountTest.gdb"&amp;nbsp; StartTime = time.clock()&amp;nbsp; # Grab the time after importing the arcpy module (heavy), and setting workspace.&amp;nbsp; with arcpy.da.SearchCursor("RandomPoints", ["OBJECTID"]) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = {row[0] for row in cursor}&amp;nbsp; count = 0 for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1&amp;nbsp; EndTime = time.clock()&amp;nbsp; print "Finished in %s seconds" % (EndTime - StartTime) print count&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 6.75371938368 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; =============================== RESTART =============================== &amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 6.8498145457 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; =============================== RESTART =============================== &amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 6.8776609853 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;"""Method 2""" import time import arcpy&amp;nbsp; arcpy.env.workspace = "C:\CountTest.gdb"&amp;nbsp; StartTime = time.clock() # Grab the time after importing the arcpy module (heavy), and setting workspace.&amp;nbsp; arcpy.MakeTableView_management("RandomPoints", "myTableView") count = int(arcpy.GetCount_management("myTableView").getOutput(0))&amp;nbsp; EndTime = time.clock()&amp;nbsp; print "Finished in %s seconds" % (EndTime - StartTime) print "%s features" % count&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 1.68345616753 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; =============================== RESTART =============================== &amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 1.64100628447 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; =============================== RESTART =============================== &amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Finished in 1.65225749949 seconds 1000000 features &amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jul 2012 17:31:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197814#M15160</guid>
      <dc:creator>MichaelMarkieta</dc:creator>
      <dc:date>2012-07-23T17:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Is the Data Access module faster at counting features than MakeTableView + GetCou</title>
      <link>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197815#M15161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I would rather use the new data access module and Search Cursors to access my data and iterate through an object&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Given your stated desire, i'm not sure how the information you gained from your experiment (though interesting to see) is going to help you.&amp;nbsp; Given that the purpose of a cursor is to move through your data a row at a time, the factors impacting processing speed are going to be more about what other actions are being executed while you're pointed at each row.&amp;nbsp; Adding an accumulator function (count = count +1) to a series of other actions is unlikely to significantly impact processing time. I guess if all you need to do is count the features, then using the MakeTableView and implementing GetCount against that is the right way to go.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2012 12:23:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197815#M15161</guid>
      <dc:creator>ChristopherThompson</dc:creator>
      <dc:date>2012-07-24T12:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Is the Data Access module faster at counting features than MakeTableView + GetCou</title>
      <link>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197816#M15162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would do this to avoid having to loop through the records&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
with arcpy.da.SearchCursor("myFeature", ["OBJECTID"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = sorted({row[0] for row in cursor})

count = len(rows)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Given the functions in my python application, I would rather use the new data access module and Search Cursors to access my data and iterate through an object.&lt;BR /&gt;Planning for the future, which method would produce quicker results when scaled upwards (more features)?&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
with arcpy.da.SearchCursor("myFeature", ["OBJECTID"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = sorted({row[0] for row in cursor})

count = 0
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
arcpy.MakeTableView_management("myFeature", "myTableView")
count = int(arcpy.GetCount_management("myTableView").getOutput(0))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:52:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-the-data-access-module-faster-at-counting/m-p/197816#M15162</guid>
      <dc:creator>LorneDmitruk</dc:creator>
      <dc:date>2021-12-11T09:52:46Z</dc:date>
    </item>
  </channel>
</rss>

