The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

<!-- Presentation generated by Internet Assistant for Microsoft PowerPoint 97 -->
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft Internet Assistant for Microsoft PowerPoint 97">
<TITLE>Sling less for speed</TITLE>
</HEAD>
<BODY >
<CENTER>
<TABLE WIDTH=100%>
<TR> <TD WIDTH=100% ALIGN=CENTER>
<A HREF="sld001.htm">First</A>&nbsp;&nbsp;
<A HREF="sld017.htm">Previous</A>&nbsp;&nbsp;
<A HREF="sld019.htm">Next</A>&nbsp;&nbsp;
<A HREF="sld096.htm">Last</A>&nbsp;&nbsp;
&nbsp;&nbsp; <A HREF="index.htm">Index</A>&nbsp;&nbsp;
<A HREF="dbi.perl.org">Home</A>&nbsp;&nbsp;
<A HREF="tsld018.htm">Text</A>&nbsp;&nbsp;
</TD> </TR>
<TR> <TD WIDTH=100% ALIGN=CENTER>
<IMG SRC="img018.gif" usemap="#Objmap" WIDTH=800 HEIGHT=600 BORDER=0>
</TD> </TR>
</TABLE>
<P>Slide 18 of 96</P>
</CENTER>
<!-- <UL>
<H2>Sling less for speed</H2>
</UL></P>
<P><UL>
<LI><H2>while(@row = $sth-&#062fetchrow_array) { }
</H2>
<UL>
<LI>one column: 51,155 fetches per second
<LI>20 columns: 24,032 fetches per second
</UL></UL><UL>
<H2>
</H2>
</UL><UL>
<LI><H2>while($row = $sth-&#062fetchrow_arrayref) { }
</H2>
<UL>
<LI>one column: 58,653 fetches per second - approximately 12% faster
<LI>20 columns: 49,390 fetches per second - approximately 51% faster
</UL></UL><UL>
<H2>
</H2>
</UL><UL>
<LI><H2>while($row = shift(@$rowcache) || shift(@{$rowcache=$sth-&#062fetchall_arrayref(undef, $max_rows)})) { }
</H2>
<UL>
<LI>one column: 348,140 fetches per second - by far the fastest!
<LI>20 columns: 42,128 fetches per second - now slower than fetchrow_arrayref!
<LI>Why? Balance time saved making fewer calls with time spent managing more memory
<LI>Do your own benchmarks to find what works best for your situations
</UL></UL><UL>
<H2>
</H2>
</UL><UL>
<LI><H2>Notes:
</H2>
<UL>
<LI>Tests used DBD::mysql on 100,000 rows with fields 9 chars each. $max_rows=1000;
<LI>Time spent inside fetchrow_* method is approximately 0.000011s (~90,000 per second)</UL></UL></P>
<P> -->
</Body>
</HTML>