-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDemo2.java
More file actions
27 lines (23 loc) · 864 Bytes
/
Demo2.java
File metadata and controls
27 lines (23 loc) · 864 Bytes
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
public class Demo2 {
public static void main(String[] args) {
// Big O Notation
String a = "amit";
String b = null;
Runtime r = Runtime.getRuntime();
//System.nanoTime()
System.out.println("Total Heap Size "+r.totalMemory());
System.out.println("Free Heap Size "+r.freeMemory());
System.out.println("Used Heap Size "+(r.totalMemory()-r.freeMemory()));
long startTime = System.currentTimeMillis();
for(int i = 1; i<=100000 ; i++){
b="amit";
//b= new String("amit");
}
long endTime = System.currentTimeMillis();
System.out.println("***********************************");
System.out.println("Total Heap Size "+r.totalMemory());
System.out.println("Free Heap Size "+r.freeMemory());
System.out.println("Used Heap Size "+(r.totalMemory()-r.freeMemory()));
System.out.println("Total Time Taken "+(endTime-startTime));
}
}