digitalmars.D - member access times
- spir (33/33) Dec 29 2010 Hello,
- Vladimir Panteleev (7/11) Dec 29 2010 Perhaps you could post the source code you used for the benchmark, to ma...
- bearophile (6/8) Dec 29 2010 import std.c.stdlib: malloc; // deprecated
Hello,
Out of curiosity, I did some timings of data & function member access on st=
ructs & classes. Actually, to check whether (explicity) referenced structs =
would ~ behave like classes in this respect, I added a struct element alloc=
ated via
auto ps =3D cast(S*)(GC.malloc(S.sizeof));
*ps =3D S();
To complete the picture, and because I will need something similar for a la=
ter project, I also added a class element (doubly) referenced using the sam=
e idiom.
Here are rough typical results in %:
member direct struct normal class ref'ed struct 2ref'ed class
data 150 100 110 150
function 200 540 200 600
I'm surprised by 150 for direct struct data access compared to a simply-ref=
erenced element. ??? Would someone confirm this result? (Timings are rather=
unstable but this ratio of ~ 1.5 clearly appears.)
Note: for _static_ member functions, times are roughly equal for all cases =
(~ 215%).
Just for information,
Denis
PS: A few additional points:
The online doc (for D2) about core.memory is outdated. Funcs like malloc & =
free are (now) integrated as static funcs inside the GC struct, as shown ab=
ove. The module's inline doc is correct, only needs to be uploaded.
Will a doubly-referenced class element allocated like above (1 explicite + =
1 implicite refs)be properly memory-managed (meaning not freed as long as =
pc lives, and freed when it ends if no other ref exists).
[Also, I could not find how to get a row malloc (un-GC'ed), while indeed D =
must have one --probably C's directly, but where is it made available?]
-- -- -- -- -- -- --
vit esse estrany =E2=98=A3
spir.wikidot.com
Dec 29 2010
On Wed, 29 Dec 2010 13:14:34 +0200, spir <denis.spir gmail.com> wrote:I'm surprised by 150 for direct struct data access compared to a simply-referenced element. ??? Would someone confirm this result?Perhaps you could post the source code you used for the benchmark, to make this easier?[Also, I could not find how to get a row malloc (un-GC'ed), while indeed D must have one --probably C's directly, but where is it made available?]malloc from core.stdc.stdlib? -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Dec 29 2010
spir:Note: for _static_ member functions, times are roughly equal for all cases (~ 215%).Keep in mind that (in theory) true static values need __gshared.[Also, I could not find how to get a row malloc (un-GC'ed), while indeed D must have one --probably C's directly, but where is it made available?]import std.c.stdlib: malloc; // deprecated import core.stdc.stdlib: malloc; Bye, bearophile
Dec 29 2010









"Vladimir Panteleev" <vladimir thecybershadow.net> 