Commit 8cd2956
authored
Optimize Workload.repeatString
The original implementation repeatedly concatenated strings in a loop (`result = result + s`), which in Java creates a new String object on every iteration because Strings are immutable, resulting in O(n²) time complexity and ~1.3 seconds spent in that single line (90.9% of total runtime per profiler). The optimized version replaces this with `String.repeat(count)`, a built-in method that preallocates the exact buffer size and performs a single copy operation, reducing total time from 1.43s to 0.0074s—a 520% speedup. The change preserves original behavior by using `String.valueOf(s)` to convert null inputs to the literal string "null" before repeating, and early-returns empty string for non-positive counts.1 parent f3eecac commit 8cd2956
1 file changed
Lines changed: 5 additions & 4 deletions
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
| 17 | + | |
| 18 | + | |
20 | 19 | | |
21 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
0 commit comments