Skip to content

Commit 71917e3

Browse files
committed
[auto] Reflect the changes of main repository.
1 parent ed4bca6 commit 71917e3

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

README.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,63 @@
55
- 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).
66
- Feel free to fork or copy to your own codebase.
77

8+
## Example
89

10+
### output
11+
<p align="center">
12+
13+
</p>
14+
<p align="center">
15+
<img src="img/result.png" width="886" alt="result.png">
16+
</p>
17+
18+
### code
19+
20+
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 in 1..3000) {
39+
str += i.toString()
40+
}
41+
str
42+
}
43+
44+
block("StringBuilder") {
45+
val sb = StringBuilder()
46+
for (i in 1..3000) {
47+
sb.append(i.toString())
48+
}
49+
sb.toString()
50+
}
51+
52+
block("StringBuffer") {
53+
val sb = StringBuffer()
54+
for (i in 1..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.
965

1066
## 🟦 Single-File version Dependency
1167

@@ -34,7 +90,7 @@ repositories {
3490
}
3591
3692
dependencies {
37-
implementation 'com.github.nyabkun:qq-benchmark:v2023-05-22'
93+
implementation 'com.github.nyabkun:qq-benchmark:v2023-05-24'
3894
}
3995
```
4096

@@ -46,7 +102,7 @@ repositories {
46102
}
47103

48104
dependencies {
49-
implementation("com.github.nyabkun:qq-benchmark:v2023-05-22")
105+
implementation("com.github.nyabkun:qq-benchmark:v2023-05-24")
50106
}
51107
```
52108

@@ -65,7 +121,7 @@ dependencies {
65121
<dependency>
66122
<groupId>com.github.nyabkun</groupId>
67123
<artifactId>qq-benchmark</artifactId>
68-
<version>v2023-05-22</version>
124+
<version>v2023-05-24</version>
69125
</dependency>
70126
</dependencies>
71127
```

0 commit comments

Comments
 (0)