mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
Migrate Java code to separate QL repo.
This commit is contained in:
18
java/ql/src/Performance/ConcatenationInLoops.java
Normal file
18
java/ql/src/Performance/ConcatenationInLoops.java
Normal file
@@ -0,0 +1,18 @@
|
||||
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.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user