member access times

spir denis.spir at gmail.com
Wed Dec 29 03:14:34 PST 2010


Hello,


Out of curiosity, I did some timings of data & function member access on structs & classes. Actually, to check whether (explicity) referenced structs would ~ behave like classes in this respect, I added a struct element allocated via
    auto ps = cast(S*)(GC.malloc(S.sizeof));
    *ps = S();
To complete the picture, and because I will need something similar for a later project, I also added a class element (doubly) referenced using the same 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-referenced 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 above. 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 ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list