Null references redux + Cyclone

bearophile bearophileHUGS at lycos.com
Mon Sep 28 12:36:05 PDT 2009


Christopher Wright:

> > Certainly agreed on virtual calls: on my machine, I timed a simple 
> > example as executing 65 interface calls per microsecond, 85 virtual 
> > calls per microsecond, and 210 non-member function calls per 
> > microsecond. So you should almost never worry about the cost of 
> > interface calls since they're so cheap, but they are 3.5 times slower 
> > than non-member functions.

The main problem of virtual calls in D are the missed inlining opportunities.

------------

Andrei Alexandrescu:

> I seem to recall that 
> interface dispach in D does a linear search in the interfaces list, so 
> you may want to repeat your tests with a variable number of interfaces, 
> and a variable position of the interface being used.

The following is a D port of the well known "Richards" benchmark. This specific version is object oriented, its classes are final (otherwise the code gets quite slower with LDC) and it has getters/setters. It contains an interface:
http://codepad.org/kO3MJK60

You can run it at the command line giving it 10000000.

On a Celeron 2 GHz if you replace the interface with an abstract class the running time goes from 2.16 to 1.58 seconds, compiled with:
ldc -O5 -release -inline

Compiled with DMD the running time seems about unchanged. I have no idea why. Maybe some of you can tell me.

In a day or two I'll release many more timings and tests about this Richards benchmark.

Bye,
bearophile



More information about the Digitalmars-d mailing list