mirror of
https://github.com/github/codeql.git
synced 2025-12-25 05:06:34 +01:00
18 lines
580 B
Java
18 lines
580 B
Java
public class ConcatenationInLoops {
|
|
public static void main(String[] args) {
|
|
Random r = new Random(123);
|
|
long start = System.currentTimeMillis();
|
|
String s = "";
|
|
for (int i = 0; i < 65536; i++)
|
|
s += r.nextInt(2);
|
|
System.out.println(System.currentTimeMillis() - start); // This prints roughly 4500.
|
|
|
|
r = new Random(123);
|
|
start = System.currentTimeMillis();
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int i = 0; i < 65536; i++)
|
|
sb.append(r.nextInt(2));
|
|
s = sb.toString();
|
|
System.out.println(System.currentTimeMillis() - start); // This prints 5.
|
|
}
|
|
} |