]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/testcases/org/simantics/db/common/utils/URITest.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.common / testcases / org / simantics / db / common / utils / URITest.java
1 package org.simantics.db.common.utils;
2
3 import java.io.UnsupportedEncodingException;
4 import java.net.URLDecoder;
5 import java.net.URLEncoder;
6
7 import org.simantics.databoard.util.URIStringUtils;
8
9 public class URITest {
10
11     private static final int COUNT = 1000000;
12     private static final String TEST_STR = "http://www.simantics.org/Layer0-1.0/HasInverse/Inverse";
13     //private static final String TEST_STR = "http--www.simantics.org-Layer0-1.0-HasInverse-Inverse";
14
15     public static void main(String[] args) {
16         try {
17             String s1 = URLEncoder.encode(TEST_STR, "UTF-8");
18             String s2 = URIStringUtils.escape(TEST_STR);
19             System.out.println("URLEncoder.encode(" + TEST_STR + "): " + s1);
20             System.out.println("URIStringUtils.escapeAll(" + TEST_STR + "): " + s2);
21             String ds1 = URLDecoder.decode(s1, "UTF-8");
22             String ds2 = URIStringUtils.unescape(s2);
23             System.out.println("ds1: " + ds1);
24             System.out.println("ds2: " + ds2);
25             String ds1x2 = URIStringUtils.unescape(s2);
26             String ds2x1 = URLDecoder.decode(s1, "UTF-8");
27             System.out.println("ds1x2: " + ds1x2);
28             System.out.println("ds2x1: " + ds2x1);
29
30             long start = System.nanoTime();
31             for (int i = 0; i < COUNT; ++i) {
32                 String s = URLEncoder.encode(TEST_STR, "UTF-8");
33             }
34             long end = System.nanoTime();
35             System.out.println("URLEncoder: " + ((end-start)*1e-9));
36
37             long start2 = System.nanoTime();
38             for (int i = 0; i < COUNT; ++i) {
39                 String s = URIStringUtils.escape(TEST_STR);
40             }
41             long end2 = System.nanoTime();
42             System.out.println("URIStringUtils.escape: " + ((end2-start2)*1e-9));
43
44             long start3 = System.nanoTime();
45             for (int i = 0; i < COUNT; ++i) {
46                 String s = URLDecoder.decode(ds1, "UTF-8");
47             }
48             long end3 = System.nanoTime();
49             System.out.println("URLDecoder: " + ((end3-start3)*1e-9));
50
51             long start4 = System.nanoTime();
52             for (int i = 0; i < COUNT; ++i) {
53                 String s = URIStringUtils.unescape(ds2);
54             }
55             long end4 = System.nanoTime();
56             System.out.println("URIStringUtils.decode: " + ((end4-start4)*1e-9));
57
58         } catch (UnsupportedEncodingException e1) {
59             e1.printStackTrace();
60         }
61     }
62
63 }