forked from 17mon/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestMain.java
More file actions
61 lines (51 loc) · 1.96 KB
/
TestMain.java
File metadata and controls
61 lines (51 loc) · 1.96 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.nio.charset.Charset;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
class TestMain {
public static void main(String[] args){
IPOld.load("/Users/york/htdocs/kankan-mp4-extractor/libs/ipip/17monipdb.dat");
IP.load("/Users/york/htdocs/kankan-mp4-extractor/libs/ipip/17monipdb.dat");
final int testSize = 100 * 10000;
String[] ips = new String[testSize];
for(int i=0; i<testSize; i++){
ips[i] = IP.randomIp();
}
ips[0] = "119.147.158.186";
ips[1] = "223.136.200.228";
ips[2] = "68.104.105.223";
ips[3] = "1.64.29.228";
System.out.println("ip random completed");
// check that the return value of new implement and old implement are the same
for(int i=0; i<testSize; i++){
String[] newReturn = IP.find(ips[i]);
String[] oldReturn = IPOld.find(ips[i]);
if (!Arrays.deepEquals(newReturn, oldReturn)) {
System.out.println("ip info not equal for: " + ips[i]);
System.out.println(Arrays.toString(newReturn));
System.out.println(Arrays.toString(oldReturn));
System.exit(1);
}
}
// compare the performance
Long startNew = System.nanoTime();
for(int i=0; i<testSize; i++){
IP.find(ips[i]);
}
Long endNew = System.nanoTime();
System.out.println("execute time of new implement is: " + (endNew - startNew) / 1000 / 1000);
Long startOld = System.nanoTime();
for(int i=0; i<testSize; i++){
IPOld.find(ips[i]);
}
Long endOld = System.nanoTime();
System.out.println("execute time of old implement is: " + (endOld - startOld) / 1000 / 1000);
}
}