You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-3Lines changed: 59 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,63 @@
5
5
- Just copy and paste 🟦 Single-File version [QBenchmark.kt](src-single/QBenchmark.kt) into your project.- Or you can use 🟩 Split-File Jar version. See [Maven Dependency Section](#-split-file-jar-version-maven-dependency).
Full Source [QBenchmarkExample.kt](src-example/QBenchmarkExample.kt)
21
+
22
+
```kotlin
23
+
qBenchmark {
24
+
// Number of trials
25
+
nTry =500
26
+
27
+
// If this instance has several [block]s, it will shuffle them in randomized order and measure the time.
28
+
// [nSingleMeasureLoop] represents how many times a block is executed in one measurement.
29
+
// Eventually, the code snippet in the [block] will be executed [nSingleMeasureLoop] * [nTry] times.
30
+
nSingleMeasureLoop =5
31
+
32
+
// In the early executions, the execution of the [block] takes more time,
33
+
// so we first perform some executions which are not counted in the measurements.
34
+
nWarmUpTry =50
35
+
36
+
block("Raw String Concat") {
37
+
var str =""
38
+
for (i in1..3000) {
39
+
str += i.toString()
40
+
}
41
+
str
42
+
}
43
+
44
+
block("StringBuilder") {
45
+
val sb =StringBuilder()
46
+
for (i in1..3000) {
47
+
sb.append(i.toString())
48
+
}
49
+
sb.toString()
50
+
}
51
+
52
+
block("StringBuffer") {
53
+
val sb =StringBuffer()
54
+
for (i in1..3000) {
55
+
sb.append(i.toString())
56
+
}
57
+
sb.toString()
58
+
}
59
+
}
60
+
```
61
+
62
+
Please see [QBenchmarkTest.kt](src-test-split/nyab/util/QBenchmarkTest.kt) for more code examples.
63
+
Single-File version [src-test-single/QBenchmarkTest.kt](src-test-single/QBenchmarkTest.kt) is a self-contained source code that includes a runnable main function.
64
+
You can easily copy and paste it into your codebase.
0 commit comments