-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProblem.java
More file actions
30 lines (29 loc) · 1.38 KB
/
Problem.java
File metadata and controls
30 lines (29 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class Problem {
public static void main(String[] args) {
StringBuffer sql = new StringBuffer("select * from products where price = "); // len + capacity
System.out.println(sql.length());
System.out.println(sql.capacity());
// sql.ensureCapacity(1000);
sql.append(
"Okgjkdfhgkjgjkdhdfgfdffhgjdfhkjghfjkghfdjkghjkdfghkjfdhghdjkghjkdfhgkjdfjkghdjkfhgfdhgjkdhgkjhdfjkghjkfdhgjkfdhg");
System.out.println(sql.length());
System.out.println(sql.capacity());
sql.append("Ok");
System.out.println(sql.length());
System.out.println(sql.capacity());
long price = 1;
Runtime runtime = Runtime.getRuntime(); // Singleton
System.out.println("Total " + runtime.totalMemory() + " Free " +
runtime.freeMemory() + " Used "
+ (runtime.totalMemory() - runtime.freeMemory()));
long startTime = System.currentTimeMillis();
for (price = 1; price <= 100000; price++) {
// sql = sql + price;
sql.append(price);
}
long endTime = System.currentTimeMillis();
System.out.println("Total Time Taken " + (endTime - startTime) + " ms");
System.out.println("Total " + runtime.totalMemory() + " Free " + runtime.freeMemory() + " Used "
+ (runtime.totalMemory() - runtime.freeMemory()));
}
}