A new version of KotlinPrimavera, now including a lttile DSL for using StopWatch
[ContextConfiguration]
public class PerformanceTest : JdbcTestBase() {
[Autowired] var template: JdbcTemplate? = null
[Test]
fun performance() {
//Creates an stopwatch
val watch = stopWatch() {
for (i in 1…10) {
//Now everything inside the task body will be measured
task(“With DSL as parameter: $i run”) {
val result = template!!.query(select, mapperFunction)
Assert.assertEquals(result.size(), 1000)
}
task("With DSL in line: $i run ") {
val result = template!!.query(select) { rs, i ->
rs.extract {
TestBean(int[“id”]!!,
string[“description”]!!,
date[“create_date”]!!)
}
}
Assert.assertEquals(result.size(), 1000)
}
task(“Without DSL: $i run”) {
val result = template!!.query(select) { rs, i ->
TestBean(rs.getInt(“id”),
rs.getString(“description”)!!,
rs.getDate(“create_date”)!!)
}
Assert.assertEquals(result.size(), 1000)
}
task(“Without SAM: i</span> run<span >"</span></span>) {
<span >val</span> <span >result</span> <span >=</span> template<span >!!</span><span >.</span>query(select, object <span >:</span> RowMapper<TestBean> {
<span >override</span> <span >fun</span> <span >mapRow</span>(<span >rs</span><span >:</span> ResultSet, <span >rowNum</span><span >:</span> <span >Int</span>)<span >:</span> TestBean {
<span >return</span> TestBean(rs<span >.</span>getInt(<span ><span >"</span>id<span >"</span></span>),
rs<span >.</span>getString(<span ><span >"</span>description<span >"</span></span>)<span >!!</span>,
rs<span >.</span>getDate(<span ><span >"</span>create_date<span >"</span></span>)<span >!!</span>)
}
})
Assert<span >.</span>assertEquals(result<span >.</span>size(), <span >1000</span>)
}
}
}
println(<span ><span >"</span>watch.prettyPrint() = <span >{watch.prettyPrint()}”)
}
}
That will print
watch.prettyPrint() = StopWatch '': running time (millis) = 325
-----------------------------------------
ms % Task name
-----------------------------------------
00055 017% With DSL as parameter: 1 run
00042 013% With DSL in line: 1 run
00032 010% Without DSL: 1 run
00021 006% Without SAM: 1 run
00022 007% With DSL as parameter: 2 run
00016 005% With DSL in line: 2 run
00008 002% Without DSL: 2 run
00008 002% Without SAM: 2 run
00009 003% With DSL as parameter: 3 run
00010 003% With DSL in line: 3 run
00006 002% Without DSL: 3 run
00007 002% Without SAM: 3 run
00008 002% With DSL as parameter: 4 run
00006 002% With DSL in line: 4 run
00003 001% Without DSL: 4 run
00003 001% Without SAM: 4 run
00005 002% With DSL as parameter: 5 run
00007 002% With DSL in line: 5 run
00003 001% Without DSL: 5 run
00002 001% Without SAM: 5 run
00005 002% With DSL as parameter: 6 run
00005 002% With DSL in line: 6 run
00003 001% Without DSL: 6 run
00001 000% Without SAM: 6 run
00004 001% With DSL as parameter: 7 run
00004 001% With DSL in line: 7 run
00002 001% Without DSL: 7 run
00001 000% Without SAM: 7 run
00004 001% With DSL as parameter: 8 run
00004 001% With DSL in line: 8 run
00002 001% Without DSL: 8 run
00002 001% Without SAM: 8 run
00002 001% With DSL as parameter: 9 run
00002 001% With DSL in line: 9 run
00002 001% Without DSL: 9 run
00002 001% Without SAM: 9 run
00002 001% With DSL as parameter: 10 run
00002 001% With DSL in line: 10 run
00001 000% Without DSL: 10 run
00002 001% Without SAM: 10 run
More info in the Wiki