Empty struct, any runtime cost?
SimonN via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 19 02:54:31 PDT 2015
Hi,
in a release-like build, I'm using the tharsis profiler, which is
a
frame-based profiler. Zone is a RAII struct that measures how
long its own
lifetime is.
with (Zone(my_profiler, "zone name to appear in output")) {
do_expensive_work();
do_some_more_work();
}
// Zone goes out of scope here
I would like to use this code without modification in a release
build
without profiling. I would rather not put version statements
everywhere.
I have only one version statement in a single file that's
included by
all files doing profiling:
version (release_with_profiling) {
public import tharsis.prof;
}
else {
class Profiler { }
struct Zone { this(Profiler, string) { } }
}
Using that, the first code sample compiles in the non-profiling
build,
where Zone is an empty struct.
* Will the empty struct get optimized away completely by the
compiler,
at least if we pass -O -inline? I'd really like that, I have
profiling code in several inner loops.
* If not, what other approach could be usable to keep
boilerplate in
most source files to a minimum?
-- Simon
More information about the Digitalmars-d-learn
mailing list