Properties set/get huge speed difference?
ephemeros
ephemeros at gmail.com
Fri Sep 15 19:14:43 PDT 2006
Hello,
anyone knows why getting/setting the class properties by invoking the
methods is so slow (~20 times slower - gdc/ubuntu/amd32) comparing with
doing the same things directly, with the "=" operator (public
properties)? this matters in an app with thousands of evaluations per
loop, also the methods are needed to compose different behaviors, etc.
i give here a little "get" example:
//=======================
// src/clasamare.d
module src.clasamare;
class ClasaMare
{
//private:
float val;
//public:
void value(float newValue)
{
val=newValue;
}
float value()
{
return val;
}
}
//=========================
this runs slower(~0.450s):
//=========================
// src/test.d
import src.clasamare;
import std.cstream;
int main()
{
ClasaMare cls1=new ClasaMare();
for(uint i=0; i<100000000; i++)
{
cls1.value=15.7;
}
dout.writefln("%f", cls1.value);
return 0;
}
//==========================
this is faster(~0.020s):
//=========================
// src/test.d
import src.clasamare;
import std.cstream;
int main()
{
ClasaMare cls1=new ClasaMare();
for(uint i=0; i<100000000; i++)
{
cls1.val=15.7;
}
dout.writefln("%f", cls1.value);
return 0;
}
//==========================
i compiled with this command:
gdc -frelease -s -O3 -fomit-frame-pointer -mmmx -msse -mfpmath=sse
-mfancy-math-387 -minline-all-stringops -fschedule-insns2
-frerun-loop-opt -frerun-cse-after-loop -funroll-loops
-fexpensive-optimizations -finline-functions -o made test.d
src/clasamica.d src/clasamare.d
when i compile with:
gdmd -O -release -inline test.d src/clasamica.d src/clasamare.d
the times are 0.450s/0.150s
thank you
More information about the Digitalmars-d-learn
mailing list