I’m trying to get sbt to compile and build some benchmarks. I’ve told it to add the benchmarks to the test path so they’re recompiled along with tests, but I can’t figure out how to write an action to let me actually run them. Is it possible to invoke classes from the Project definition class, or even just from the command line?
Share
Yes, it is.
If you’d like to run them in the same VM the SBT is run in, then write a custom task similar to the following in your project definition file:
Typing
benchmarkin SBT console will run the task above. To actually run the benchmarks, or, for that matter, any other class you’ve compiled, you can reuse some of the existing infrastructure of SBT, namely the methodrunTaskwhich will create a task that runs something for you. It has the following signature:Simply add the following to your file:
When running benchmarks, it is sometimes recommended that you run them in a separate jvm invocation, to get more reliable results. SBT allows you to run separate processes by invoking a method
!on a string command. Say you have a commandjava -jar path-to-artifact.jaryou want to run. Then:runs the command in SBT. You want to put the snippet above in a separate task, same as earlier.
And don’t forget to
reloadwhen you change your project definition.