Hi.
I compared performance between object instantiation and object cloning. I
was wondering that instantiation almost twice faster than clone (primitive
70 vs 148).
Could you explain why it like that and could it be improved?
I was think that new object construction is much complex because it
requires to fill all object fields (header structure and etc).
And I was think that copy is just simple function like memcpy which just
copy bytes without any logic.
Here is my code:
object := Object new.
3 timesRepeat: [ Smalltalk garbageCollect ].
result1 := [ Object basicNew ] benchFor: 10 seconds.
3 timesRepeat: [ Smalltalk garbageCollect ].
result2 := [ object shallowCopy ] benchFor: 10 seconds.
{result1. result2}.
"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))"
(I run it on latest Pharo on Mac SpurVM)
Best regards,
Denis