<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>I know the CastImageFilter is no the most exciting filter but, it's probably the most frequently used and should be as snappy as possible. And the lessons learn here should be applicable to many other places.</div><div><br></div><div>I am clamming that I have speed this guy up by 5-25X from ITK v4.3.2 when the following two patch are combined:</div><div><br></div><div><div><a href="http://review.source.kitware.com/#/c/11174/">http://review.source.kitware.com/#/c/11174/</a></div><div><a href="http://review.source.kitware.com/#/c/11163/">http://review.source.kitware.com/#/c/11163/</a></div></div><div><br></div><div>I have to thank Kent for motivating the use of using std:copy for conversion to get most of this gain, in ImageAlgorithm::Copy.</div><div><br></div><div>The following performance was measure by converting short to float, with the following loop:</div><div><br></div><div><div>const unsigned int cnt = 5;</div><div><br></div><div> for ( unsigned int j = 0; j < 10; ++j )</div><div> {</div><div> t.Start();</div><div> for ( unsigned int i = 0; i < cnt; ++i )</div><div> {</div><div> inImage1->Modified();</div><div> f->Update();</div><div> }</div><div> t.Stop();</div><div> }</div><div><br></div><div> std::cout << "\t+Add Average Time: " << t.GetMean()/cnt << t.GetUnit() << std::endl;</div></div><div><br></div><div><br></div><div>I hope the follow table get formatted OK over e-mail:</div><div><br></div><div>
<table border="0" cellpadding="0" cellspacing="0" width="607" style="border-collapse: collapse; width: 607pt; position: static; z-index: auto; ">
<!--StartFragment-->
<colgroup><col width="81" style="mso-width-source:userset;mso-width-alt:3456;width:81pt">
<col width="71" style="mso-width-source:userset;mso-width-alt:3029;width:71pt">
<col width="65" span="7" style="width:65pt">
</colgroup><tbody><tr height="35" style="mso-height-source:userset;height:35.0pt">
<td height="35" class="xl69" width="81" style="height:35.0pt;width:81pt">gcc 4.4.7</td>
<td class="xl66" width="71" style="width:71pt">4.3.2</td>
<td class="xl66" width="65" style="width:65pt">master</td>
<td class="xl66" width="65" style="width:65pt">w/ std::copy</td>
<td class="xl66" width="65" style="width:65pt"></td>
<td class="xl66" width="65" style="width:65pt"></td>
<td class="xl66" width="65" style="width:65pt">master speedup</td>
<td class="xl66" width="65" style="width:65pt">incremental speedup</td>
<td class="xl66" width="65" style="width:65pt">total speedup</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[64, 64, 64]</td>
<td class="xl64" align="right">0.0023021</td>
<td class="xl64" align="right">0.0007273</td>
<td class="xl64" align="right">0.0001291</td>
<td></td>
<td></td>
<td align="right">3.16510482</td>
<td align="right">5.633172757</td>
<td align="right">17.82958224</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[128, 128, 128]</td>
<td class="xl64" align="right">0.0169621</td>
<td class="xl64" align="right">0.0043321</td>
<td class="xl64" align="right">0.0010102</td>
<td></td>
<td></td>
<td align="right">3.915409013</td>
<td align="right">4.28822854</td>
<td align="right">16.79016867</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[256, 256, 256]</td>
<td class="xl64" align="right">0.1418440</td>
<td class="xl64" align="right">0.0306757</td>
<td class="xl64" align="right">0.0238598</td>
<td></td>
<td></td>
<td align="right">4.623985761</td>
<td align="right">1.285664591</td>
<td align="right">5.94489476</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[32, 32]</td>
<td class="xl64" align="right">0.0000141</td>
<td class="xl64" align="right">0.0000064</td>
<td class="xl64" align="right">0.0000037</td>
<td></td>
<td></td>
<td align="right">2.182823223</td>
<td align="right">1.732051203</td>
<td align="right">3.780761589</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[64, 64]</td>
<td class="xl64" align="right">0.0000364</td>
<td class="xl64" align="right">0.0000116</td>
<td class="xl64" align="right">0.0000034</td>
<td></td>
<td></td>
<td align="right">3.12844542</td>
<td align="right">3.417944909</td>
<td align="right">10.6928541</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[128, 128]</td>
<td class="xl64" align="right">0.0001251</td>
<td class="xl64" align="right">0.0000319</td>
<td class="xl64" align="right">0.0000077</td>
<td></td>
<td></td>
<td align="right">3.920922622</td>
<td align="right">4.163037648</td>
<td align="right">16.32294849</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[256, 256]</td>
<td class="xl64" align="right">0.0004688</td>
<td class="xl64" align="right">0.0001040</td>
<td class="xl64" align="right">0.0000190</td>
<td></td>
<td></td>
<td align="right">4.50977299</td>
<td align="right">5.469650176</td>
<td align="right">24.66688063</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl69" style="height:15.0pt">gcc 4.7.1</td>
<td></td>
<td></td>
<td class="xl64"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[64, 64, 64]</td>
<td class="xl67" align="right">0.00162290</td>
<td class="xl64" align="right">0.0004971</td>
<td class="xl64" align="right">0.0001243</td>
<td></td>
<td></td>
<td align="right">3.264998189</td>
<td align="right">3.999420677</td>
<td align="right">13.05810127</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[128, 128, 128]</td>
<td class="xl67" align="right">0.01117240</td>
<td class="xl64" align="right">0.0022267</td>
<td class="xl64" align="right">0.0009529</td>
<td></td>
<td></td>
<td align="right">5.017424732</td>
<td align="right">2.336883002</td>
<td align="right">11.72513457</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[256, 256, 256]</td>
<td class="xl67" align="right">0.08918900</td>
<td class="xl64" align="right">0.0228131</td>
<td class="xl64" align="right">0.0236030</td>
<td></td>
<td></td>
<td align="right">3.909551968</td>
<td align="right">0.966533915</td>
<td align="right">3.77871457</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[32, 32]</td>
<td class="xl67" align="right">0.00001120</td>
<td class="xl64" align="right">0.0000058</td>
<td class="xl64" align="right">0.0000036</td>
<td></td>
<td></td>
<td align="right">1.916726871</td>
<td align="right">1.631158459</td>
<td align="right">3.126485249</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[64, 64]</td>
<td class="xl67" align="right">0.00002628</td>
<td class="xl64" align="right">0.0000075</td>
<td class="xl64" align="right">0.0000032</td>
<td></td>
<td></td>
<td align="right">3.48356744</td>
<td align="right">2.371815752</td>
<td align="right">8.262380129</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[128, 128]</td>
<td class="xl67" align="right">0.00008760</td>
<td class="xl64" align="right">0.0000140</td>
<td class="xl64" align="right">0.0000074</td>
<td></td>
<td></td>
<td align="right">6.257173266</td>
<td align="right">1.891748001</td>
<td align="right">11.83699502</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[256, 256]</td>
<td class="xl67" align="right">0.00031716</td>
<td class="xl64" align="right">0.0000317</td>
<td class="xl64" align="right">0.0000191</td>
<td></td>
<td></td>
<td align="right">10.00511039</td>
<td align="right">1.656612056</td>
<td align="right">16.5745865</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl69" style="height:15.0pt">icc 13.0.1</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[64, 64, 64]</td>
<td class="xl64" align="right">0.0018701</td>
<td class="xl68" align="right">0.001209</td>
<td align="right">0.000130162</td>
<td></td>
<td></td>
<td align="right">1.546832093</td>
<td align="right">9.288425193</td>
<td align="right">14.36763418</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[128, 128, 128]</td>
<td class="xl64" align="right">0.0122367</td>
<td class="xl68" align="right">0.007942</td>
<td align="right">0.000991583</td>
<td></td>
<td></td>
<td align="right">1.540827839</td>
<td align="right">8.009052192</td>
<td align="right">12.34057058</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[256, 256, 256]</td>
<td class="xl64" align="right">0.0965067</td>
<td class="xl68" align="right">0.060345</td>
<td align="right">0.0190372</td>
<td></td>
<td></td>
<td align="right">1.599238716</td>
<td align="right">3.169867417</td>
<td align="right">5.069374698</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[32, 32]</td>
<td class="xl64" align="right">0.0000114</td>
<td class="xl68" align="right">0.000009</td>
<td class="xl63" align="right">3.28E-06</td>
<td></td>
<td></td>
<td align="right">1.246741281</td>
<td align="right">2.792150312</td>
<td align="right">3.481089056</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[64, 64]</td>
<td class="xl64" align="right">0.0000301</td>
<td class="xl68" align="right">0.000018</td>
<td class="xl63" align="right">3.22E-06</td>
<td></td>
<td></td>
<td align="right">1.715369954</td>
<td align="right">5.444456527</td>
<td align="right">9.339257142</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[128, 128]</td>
<td class="xl64" align="right">0.0001030</td>
<td class="xl68" align="right">0.000062</td>
<td class="xl63" align="right">9.04E-06</td>
<td></td>
<td></td>
<td align="right">1.663153917</td>
<td align="right">6.852245337</td>
<td align="right">11.39633867</td>
</tr>
<tr height="15" style="height:15.0pt">
<td height="15" class="xl65" style="height:15.0pt">[256, 256]</td>
<td class="xl64" align="right">0.0003961</td>
<td class="xl68" align="right">0.000221</td>
<td class="xl63" align="right">2.05E-05</td>
<td></td>
<td></td>
<td align="right">1.794484058</td>
<td align="right">10.75578251</td>
<td align="right">19.30108025</td>
</tr>
<!--EndFragment-->
</tbody></table></div></body></html>