www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - JMH

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
So this is available for Java: http://java-performance.info/jmh/. The 
framework uses attributes such as  Benchmark, 
 BenchmarkMode(Mode.AverageTime),  OutputTimeUnit(TimeUnit.MICROSECONDS) 
etc. to great effect. Far as I can imagine, runtime reflection is used.

We should do the same, just with compile-time reflection!


Andrei
Jan 20
parent reply Robert burner Schadek <rburners gmail.com> writes:
Yes, something like that would be nice. But as the website states 
you need to use maven to build the project that uses that library.

I can only suspect, but I think they use maven to collect all 
functions that use  Benchmark. And this leads to the problem the 
unittest library proposal for phobos had.

The problem was that the user had to create a custom main that 
listed all modules to check for tests or use a build tool with 
some globbing commands. Both not perfect.

""" Shameless self promoting ON """

With PR: 
https://github.com/D-Programming-Language/phobos/pull/2995

you can write:

```
void funToTest(string, int, float) {
     // funToTest impl
}

unittest {
     benchmark!funToTest();
}
```

and then you only have to pass the -unittest switch to dmd and be 
happy.

""" Shameless self promoting OFF """
Jan 20
next sibling parent reply Russel Winder via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Wed, 2016-01-20 at 21:05 +0000, Robert burner Schadek via
Digitalmars-d wrote:
 Yes, something like that would be nice. But as the website states=C2=A0
 you need to use maven to build the project that uses that library.
Or Gradle. (Technically: or Ant, or Gant, but hopefully the number of people using Ant is tending to zero very rapidly, and the number of Gant users is already 1.)
 I can only suspect, but I think they use maven to collect all=C2=A0
 functions that use  Benchmark. And this leads to the problem the=C2=A0
 unittest library proposal for phobos had.
No that is the job of the Java compiler. Gradle/Maven is just the dependency manager and build system. Think Dub.
 The problem was that the user had to create a custom main that=C2=A0
 listed all modules to check for tests or use a build tool with=C2=A0
 some globbing commands. Both not perfect.
I'll check this, I thought there was a "run everything" mode avoiding the need for custom suites. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jan 21
parent Jakob Jenkov <jakob jenkov.com> writes:
 I can only suspect, but I think they use maven to collect all 
 functions that use  Benchmark. And this leads to the problem 
 the unittest library proposal for phobos had.
No that is the job of the Java compiler.
Actually, annotations in Java can be both read at runtime or compile time. As far as I know, you cannot hook into the compiler to check for annotations, so most Java frameworks scan for annotations at startup time. Not that it matters much, anyways.
Jan 21
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2016-01-20 22:05, Robert burner Schadek wrote:

 The problem was that the user had to create a custom main that listed
 all modules to check for tests or use a build tool with some globbing
 commands. Both not perfect.
What we need is this: https://github.com/D-Programming-Language/dmd/pull/2271 -- /Jacob Carlborg
Jan 21
parent reply Chris Wright <dhasenan gmail.com> writes:
On Thu, 21 Jan 2016 13:17:04 +0100, Jacob Carlborg wrote:

 On 2016-01-20 22:05, Robert burner Schadek wrote:
 
 The problem was that the user had to create a custom main that listed
 all modules to check for tests or use a build tool with some globbing
 commands. Both not perfect.
What we need is this: https://github.com/D-Programming-Language/dmd/pull/2271
https://issues.dlang.org/show_bug.cgi?id=10023 for more context. In short, this makes user-defined attributes discoverable at runtime at the module level, if the attribute has opted in. I think. I'm not sure how it would help here, though, so I kind of doubt my interpretation.
Jan 21
parent Jacob Carlborg <doob me.com> writes:
On 2016-01-22 02:54, Chris Wright wrote:

 https://issues.dlang.org/show_bug.cgi?id=10023 for more context.

 In short, this makes user-defined attributes discoverable at runtime at
 the module level, if the attribute has opted in. I think. I'm not sure
 how it would help here, though, so I kind of doubt my interpretation.
It's discoverable at compile time as well. Currently one would need to give a list of modules where the benchmark module would look for the benchmark attributes, or something similar. With the PR I linked to that would not be necessary. One would just compile all code of interest that contains the attributes + the benchmark module. The benchmark module would basically register a callback that is called each time the compiler sees a new module. The callback would then iterate all symbols in the modules looking for the benchmark attributes. -- /Jacob Carlborg
Jan 22