forked from fredrikwidlund/libdynamic_benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorGrowJavaArrayList.java
More file actions
35 lines (32 loc) · 1 KB
/
VectorGrowJavaArrayList.java
File metadata and controls
35 lines (32 loc) · 1 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
31
32
33
34
35
import java.util.List;
import java.util.ArrayList;
public class VectorGrowJavaArrayList {
public static void main(String args[]) {
int i, n = Integer.parseInt(args[0]);
long[] m;
long j = 0, t;
List<Long> v = new ArrayList<>();
m = new long[101];
t = System.nanoTime();
m[0] = 0;
try
{
for (i = 0; i < n; i += n / 100)
{
for (j = 0; j < n / 100; j ++)
{
v.add(j);
}
m[i / (n / 100) + 1] = System.nanoTime() - t;
}
}
catch (Exception e)
{
System.out.println("Vector add " + j);
System.exit(-1);
}
System.out.println("\"size\",\"time\"");
for (i = 0; i <= 100; i ++)
System.out.printf("%d,%f\n", i * (n / 100), (float) m[i] / 1000000000f);
}
}