|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | PROPERTY | CONSTR | METHOD | DETAIL: FIELD | PROPERTY | CONSTR | METHOD |
java.lang.Objectgroovy.gbench.BenchmarkBuilder
class BenchmarkBuilder
A builder for benchmarking.
For example, you can benchmark character concatenation like the following:
def benchmarker = new BenchmarkBuilder()
def benchmarks = benchmarker.run repeat: 10000, {
def chars = ['g', 'r', 'o', 'o', 'v', 'y']
concat {
def s = ''
for(c in chars){
s.concat c
}
}
'+=' {
def s = ''
for (c in chars) {
s += c
}
}
stringbuilder {
def sb = new StringBuilder()
for(c in chars){
sb << c
}
sb.toString()
}
join {
chars.join()
}
}
benchmarks.sort().prettyPrint()
then output will be like:
user system cpu real join 46800300 15600100 62400400 91680789 stringbuilder 62400400 15600100 78000500 101281757 += 62400400 15600100 78000500 121649445 concat 46800300 31200200 78000500 129421409
Key | Value | Meaning |
---|---|---|
"gbench.cputime" | "on","off" | Enables measuring CPU time. The default value is "on". |
"gbench.trace" | "on","off" | Enables tracing in the builder to understand low-level working. The default value is "off". |
Nested Class Summary | |
---|---|
static class |
BenchmarkBuilder.Benchmarks
|
Property Summary | |
---|---|
boolean |
average
|
Benchmarks |
benchmarks
|
boolean |
cpuTimeEnabled
|
int |
idle
|
int |
repeat
|
boolean |
traceEnabled
|
boolean |
trim
|
Constructor Summary | |
BenchmarkBuilder()
|
Method Summary | |
---|---|
def
|
average(Map options = [:], Closure clos)
Gets average of benchmarks. |
def
|
each(Closure clos)
@deprecated Use |
def
|
invokeMethod(String name, Object args)
|
def
|
run(Map options = [:], Closure clos)
Gets benchmarks. |
def
|
sort()
@deprecated Use |
def
|
sum(Map options = [:], Closure clos)
Gets sum of benchmarks. |
String
|
toString()
|
def
|
with(String label, Closure clos)
Adds a code block as a benchmark target. |
Methods inherited from class Object | |
---|---|
getClass, hashCode, equals, toString, notify, notifyAll, wait, wait, wait |
Property Detail |
---|
boolean average
Benchmarks benchmarks
boolean cpuTimeEnabled
int idle
int repeat
boolean traceEnabled
boolean trim
Constructor Detail |
---|
BenchmarkBuilder()
Method Detail |
---|
def average(Map options = [:], Closure clos)
run(average: true)
options
- 1
.1
.true
, removes the highest and the lowest
benchmarks. the default value is false
.clos
- a closure to add code blocks for benchmarking
def each(Closure clos)
benchmarks.each{}
instead.
def invokeMethod(String name, Object args)
def run(Map options = [:], Closure clos)
options
- true
, gets average instead of sum. the
default value is false
(gets sum).1
.1
.true
, removes the highest and the lowest
benchmarks. the default value is false
.clos
- a closure to add code blocks for benchmarking.
def sort()
benchmarks.sort()
instead.
def sum(Map options = [:], Closure clos)
run() or run(average: false)
options
- 1
.1
.true
, removes the highest and the lowest
benchmarks. the default value is false
.clos
- a closure to add code blocks for benchmarking
String toString()
def with(String label, Closure clos)
label { code }
label
- the label of the code block.clos
- a code block.
Groovy Documentation