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

Derek Parnell derek at psych.ward
Sun Mar 26 17:20:44 PST 2006


On Mon, 27 Mar 2006 00:32:40 +0000 (UTC), Hong wrote:

> Ok, even people are telling me that class is not slower, I have decided to make
> a benchmark to test them out. Here they are,
> 
> Version using struct
> http://members.iinet.net.au/~honglee/benchmark/benchmarkstruct.d
> 
> Version using class
> http://members.iinet.net.au/~honglee/benchmark/benchmarkclass.d
> 
> On my computer, the struct version runs 300 times faster than the class version.
> Interestingly, deleting the object explicitly in the class version actually
> slowed the program even further.
> 
> The difference seems real.

On my machine, the 'class' version was 135 times slower.

I changed the 'struct' version to use a pointer (Point *p = new Point;) and
that now took 50 times slower than the first struct version.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
27/03/2006 12:05:14 PM



More information about the Digitalmars-d mailing list