<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>BTW, to better compare the two, unroll the inner loop ten times, put Object in a temp to eliminate the indirection, and use explicit temps, i.e.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">| o object |</div><div id="AppleMailSignature"><div dir="ltr"><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">o := Object new.</span></font></div><div><span style="background-color: rgba(255, 255, 255, 0);">object := Object.</span></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">3 timesRepeat: [ Smalltalk garbageCollect ].</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">result1 := [ </span></font><span style="background-color: rgba(255, 255, 255, 0);">object</span><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> basicNew. </span></font><span style="background-color: rgba(255, 255, 255, 0);">object basicNew. object basicNew. object basicNew. object basicNew. object basicNew. object basicNew. object basicNew. object basicNew. object basicNew ] benchFor: 10 seconds.</span></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">3 timesRepeat: [ Smalltalk garbageCollect ].</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">result2 := [ </span></font><span style="background-color: rgba(255, 255, 255, 0);">o shallowCopy. o shallowCopy. o shallowCopy. o shallowCopy. o shallowCopy. o shallowCopy. o shallowCopy. o shallowCopy. o shallowCopy. o shallowCopy</span><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> ] benchFor: 10 seconds.</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">{result1. result2}.</span></font></div></div><br><span style="background-color: rgba(255, 255, 255, 0);">_,,,^..^,,,_ (phone)</span></div><div><br>On Jul 29, 2016, at 2:02 AM, Denis Kudriashov <<a href="mailto:dionisiydk@gmail.com">dionisiydk@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><span></span></div></blockquote><blockquote type="cite"><div><div dir="ltr">Hi.<div><br></div><div>I compared performance between object instantiation and object cloning. I was wondering that instantiation almost twice faster than clone (primitive 70 vs 148).</div><div><br></div><div>Could you explain why it like that and could it be improved?<br></div><div><br></div><div>I was think that new object construction is much complex because it requires to fill all object fields (header structure and etc).</div><div>And I was think that copy is just simple function like memcpy which just copy bytes without any logic.</div><div><br></div><div>Here is my code:</div><div><br></div><div><div>object := Object new.</div><div>3 timesRepeat: [ Smalltalk garbageCollect ].</div><div>result1 := [ Object basicNew ] benchFor: 10 seconds.</div><div>3 timesRepeat: [ Smalltalk garbageCollect ].</div><div>result2 := [ object shallowCopy ] benchFor: 10 seconds.</div><div>{result1. result2}.</div><div> "an Array(a BenchmarkResult(518,021,045 iterations in 10 seconds 2 milliseconds. 51,791,746 per second) a BenchmarkResult(302,807,253 iterations in 10 seconds 4 milliseconds. 30,268,618 per second))" </div></div><div><br></div><div>(I run it on latest Pharo on Mac SpurVM)</div><div><br></div><div>Best regards,</div><div>Denis</div></div>
</div></blockquote></body></html>