struct vs class benchmark (was Re: Give struct the status it

Derek Parnell derek at psych.ward
Mon Mar 27 15:21:04 PST 2006


On Mon, 27 Mar 2006 15:16:38 +0000 (UTC), Dave wrote:

> In article <17vpw8ovosqie$.1f65d29ys83k6$.dlg at 40tude.net>, Derek Parnell says...
>>
>>On Mon, 27 Mar 2006 04:11:37 +0000 (UTC), Dave wrote:
>>
>>> These run as the same speed on my system, which is pretty cool since the
>>> accessor function for class Point.x is vitual. If you finalize it the class
>>> version is actually faster. No doubt the OP has a point when you try to alloc.
>>> classes in a tight loop, and I'd agree that stack allocated classes would be
>>> great, but if you can work around the allocation bottleneck then classes tend to
>>> be faster and easier to code because they are passed around by reference w/o
>>> pointer syntax.
>>
>>I wasn't so sure about the 'passed around' claim. So I amended my test to
>>pass the object and the results were almost identical. So it appears that
>>passing structs is not an issue at all. In fact, if you look at the
>>generated machine code, the struct seems to be passed by reference even if
>>you code otherwise.
>>
> 
> Not what I'm seeing - give this a try:

You're right. I was using the 'inout' paradigm which uses byRef method. If
you just use the 'in' paradigm, then it does copy struct data to the called
routine.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
28/03/2006 10:19:18 AM



More information about the Digitalmars-d mailing list