使用 simple-build-tool 进行基准测试
我正在尝试让 sbt 编译并构建一些基准测试。我已经告诉它将基准添加到测试路径中,以便它们与测试一起重新编译,但我不知道如何编写一个操作来让我实际运行它们。是否可以从项目定义类甚至仅从命令行调用类?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。
如果您想在运行 SBT 的同一虚拟机中运行它们,请在项目定义文件中编写类似于以下内容的自定义任务:
在 SBT 控制台中键入
benchmark
将运行上面的任务。要实际运行基准测试,或者您编译的任何其他类,您可以重用 SBT 的一些现有基础结构,即方法runTask
,它将创建一个运行某些内容的任务为你。它具有以下签名:只需将以下内容添加到您的文件中:
运行基准测试时,有时建议您在单独的 jvm 调用中运行它们,以获得更可靠的结果。 SBT 允许您通过在字符串命令上调用方法
!
来运行单独的进程。假设您有一个要运行的命令java -jar path-to-artifact.jar
。然后:在 SBT 中运行命令。您想将上面的代码片段放在一个单独的任务中,与之前一样。
当您更改项目定义时,不要忘记
重新加载
。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
benchmark
in 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 methodrunTask
which 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.jar
you 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
reload
when you change your project definition.难道您不能简单地将基准编写为测试,以便当您在 SBT 中调用“测试”时运行它们吗?
您还可以使用“test-only”运行特定测试,或者使用“run”或“exec”运行主程序(请参阅http://code.google.com/p/simple-build-tool/wiki/RunningSbt 了解详细信息)。
Couldn't you simply write the benchmarks as tests, so they will be run when you call 'test' in SBT?
You could also run a specific test with 'test-only', or run a main with 'run' or 'exec' (see http://code.google.com/p/simple-build-tool/wiki/RunningSbt for details).