废话不多说,原因不解释,上测试代码:
- package com.letv.cloud.cdn.jtest;
-
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
-
- import org.slf4j.LoggerFactory;
-
- import com.google.common.base.Stopwatch;
-
- public class JtestMain {
-
- private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger("JtestMain");
-
- private static Stopwatch stopWatch = new Stopwatch();
-
- public static void testList(int num){
- List<String> aList = new ArrayList<String>();
- List<String> lList = new LinkedList<String>();
- stopWatch.reset();
- stopWatch.start();
- for(int i=0; i<num; i++){
- aList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
- }
- LOGGER.info("insert num:{} ArrayList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
-
- stopWatch.reset();
- stopWatch.start();
- for(int i=0; i<num; i++){
- lList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
- }
- LOGGER.info("insert num:{} LinkedList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
- }
-
- public static void main(String[] args) throws InterruptedException, IOException {
- int[] nums = {10000,10 * 10000,100 * 10000, 1000 * 10000, 10000 * 10000};
-
- for(int i=0; i<nums.length; i++){
- testList(nums[i]);
- }
- }
- }
package com.letv.cloud.cdn.jtest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.slf4j.LoggerFactory;
import com.google.common.base.Stopwatch;
public class JtestMain {
private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger("JtestMain");
private static Stopwatch stopWatch = new Stopwatch();
public static void testList(int num){
List<String> aList = new ArrayList<String>();
List<String> lList = new LinkedList<String>();
stopWatch.reset();
stopWatch.start();
for(int i=0; i<num; i++){
aList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
}
LOGGER.info("insert num:{} ArrayList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
stopWatch.reset();
stopWatch.start();
for(int i=0; i<num; i++){
lList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
}
LOGGER.info("insert num:{} LinkedList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
}
public static void main(String[] args) throws InterruptedException, IOException {
int[] nums = {10000,10 * 10000,100 * 10000, 1000 * 10000, 10000 * 10000};
for(int i=0; i<nums.length; i++){
testList(nums[i]);
}
}
}
测试结果:
- INFO [main] (JtestMain.java:65) 11:50:47,480 -- insert num:10000 ArrayList cost:2 ms
- INFO [main] (JtestMain.java:72) 11:50:47,484 -- insert num:10000 LinkedList cost:1 ms
- INFO [main] (JtestMain.java:65) 11:50:47,490 -- insert num:100000 ArrayList cost:5 ms
- INFO [main] (JtestMain.java:72) 11:50:47,495 -- insert num:100000 LinkedList cost:5 ms
- INFO [main] (JtestMain.java:65) 11:50:47,504 -- insert num:1000000 ArrayList cost:8 ms
- INFO [main] (JtestMain.java:72) 11:50:47,515 -- insert num:1000000 LinkedList cost:11 ms
- INFO [main] (JtestMain.java:65) 11:50:47,606 -- insert num:10000000 ArrayList cost:89 ms
- INFO [main] (JtestMain.java:72) 11:50:49,335 -- insert num:10000000 LinkedList cost:1729 ms
- INFO [main] (JtestMain.java:65) 11:50:50,290 -- insert num:100000000 ArrayList cost:954 ms
- INFO [main] (JtestMain.java:72) 11:51:14,263 -- insert num:100000000 LinkedList cost:23973 ms
- package com.letv.cloud.cdn.jtest;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- import org.slf4j.LoggerFactory;
- import com.google.common.base.Stopwatch;
- public class JtestMain {
- private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger("JtestMain");
- private static Stopwatch stopWatch = new Stopwatch();
- public static void testList(int num){
- List<String> aList = new ArrayList<String>();
- List<String> lList = new LinkedList<String>();
- stopWatch.reset();
- stopWatch.start();
- for(int i=0; i<num; i++){
- aList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
- }
- LOGGER.info("insert num:{} ArrayList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
- stopWatch.reset();
- stopWatch.start();
- for(int i=0; i<num; i++){
- lList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
- }
- LOGGER.info("insert num:{} LinkedList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
- }
- public static void main(String[] args) throws InterruptedException, IOException {
- int[] nums = {10000,10 * 10000,100 * 10000, 1000 * 10000, 10000 * 10000};
- for(int i=0; i<nums.length; i++){
- testList(nums[i]);
- }
- }
- }
package com.letv.cloud.cdn.jtest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.slf4j.LoggerFactory;
import com.google.common.base.Stopwatch;
public class JtestMain {
private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger("JtestMain");
private static Stopwatch stopWatch = new Stopwatch();
public static void testList(int num){
List<String> aList = new ArrayList<String>();
List<String> lList = new LinkedList<String>();
stopWatch.reset();
stopWatch.start();
for(int i=0; i<num; i++){
aList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
}
LOGGER.info("insert num:{} ArrayList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
stopWatch.reset();
stopWatch.start();
for(int i=0; i<num; i++){
lList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
}
LOGGER.info("insert num:{} LinkedList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
}
public static void main(String[] args) throws InterruptedException, IOException {
int[] nums = {10000,10 * 10000,100 * 10000, 1000 * 10000, 10000 * 10000};
for(int i=0; i<nums.length; i++){
testList(nums[i]);
}
}
}
- INFO [main] (JtestMain.java:65) 11:50:47,480 -- insert num:10000 ArrayList cost:2 ms
- INFO [main] (JtestMain.java:72) 11:50:47,484 -- insert num:10000 LinkedList cost:1 ms
- INFO [main] (JtestMain.java:65) 11:50:47,490 -- insert num:100000 ArrayList cost:5 ms
- INFO [main] (JtestMain.java:72) 11:50:47,495 -- insert num:100000 LinkedList cost:5 ms
- INFO [main] (JtestMain.java:65) 11:50:47,504 -- insert num:1000000 ArrayList cost:8 ms
- INFO [main] (JtestMain.java:72) 11:50:47,515 -- insert num:1000000 LinkedList cost:11 ms
- INFO [main] (JtestMain.java:65) 11:50:47,606 -- insert num:10000000 ArrayList cost:89 ms
- INFO [main] (JtestMain.java:72) 11:50:49,335 -- insert num:10000000 LinkedList cost:1729 ms
- INFO [main] (JtestMain.java:65) 11:50:50,290 -- insert num:100000000 ArrayList cost:954 ms
- INFO [main] (JtestMain.java:72) 11:51:14,263 -- insert num:100000000 LinkedList cost:23973 ms