-package org.simantics.db.common.utils;\r
-\r
-import java.io.UnsupportedEncodingException;\r
-import java.net.URLDecoder;\r
-import java.net.URLEncoder;\r
-\r
-import org.simantics.databoard.util.URIStringUtils;\r
-\r
-public class URITest {\r
-\r
- private static final int COUNT = 1000000;\r
- private static final String TEST_STR = "http://www.simantics.org/Layer0-1.0/HasInverse/Inverse";\r
- //private static final String TEST_STR = "http--www.simantics.org-Layer0-1.0-HasInverse-Inverse";\r
-\r
- public static void main(String[] args) {\r
- try {\r
- String s1 = URLEncoder.encode(TEST_STR, "UTF-8");\r
- String s2 = URIStringUtils.escape(TEST_STR);\r
- System.out.println("URLEncoder.encode(" + TEST_STR + "): " + s1);\r
- System.out.println("URIStringUtils.escapeAll(" + TEST_STR + "): " + s2);\r
- String ds1 = URLDecoder.decode(s1, "UTF-8");\r
- String ds2 = URIStringUtils.unescape(s2);\r
- System.out.println("ds1: " + ds1);\r
- System.out.println("ds2: " + ds2);\r
- String ds1x2 = URIStringUtils.unescape(s2);\r
- String ds2x1 = URLDecoder.decode(s1, "UTF-8");\r
- System.out.println("ds1x2: " + ds1x2);\r
- System.out.println("ds2x1: " + ds2x1);\r
-\r
- long start = System.nanoTime();\r
- for (int i = 0; i < COUNT; ++i) {\r
- String s = URLEncoder.encode(TEST_STR, "UTF-8");\r
- }\r
- long end = System.nanoTime();\r
- System.out.println("URLEncoder: " + ((end-start)*1e-9));\r
-\r
- long start2 = System.nanoTime();\r
- for (int i = 0; i < COUNT; ++i) {\r
- String s = URIStringUtils.escape(TEST_STR);\r
- }\r
- long end2 = System.nanoTime();\r
- System.out.println("URIStringUtils.escape: " + ((end2-start2)*1e-9));\r
-\r
- long start3 = System.nanoTime();\r
- for (int i = 0; i < COUNT; ++i) {\r
- String s = URLDecoder.decode(ds1, "UTF-8");\r
- }\r
- long end3 = System.nanoTime();\r
- System.out.println("URLDecoder: " + ((end3-start3)*1e-9));\r
-\r
- long start4 = System.nanoTime();\r
- for (int i = 0; i < COUNT; ++i) {\r
- String s = URIStringUtils.unescape(ds2);\r
- }\r
- long end4 = System.nanoTime();\r
- System.out.println("URIStringUtils.decode: " + ((end4-start4)*1e-9));\r
-\r
- } catch (UnsupportedEncodingException e1) {\r
- e1.printStackTrace();\r
- }\r
- }\r
-\r
-}\r
+package org.simantics.db.common.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
+import org.simantics.databoard.util.URIStringUtils;
+
+public class URITest {
+
+ private static final int COUNT = 1000000;
+ private static final String TEST_STR = "http://www.simantics.org/Layer0-1.0/HasInverse/Inverse";
+ //private static final String TEST_STR = "http--www.simantics.org-Layer0-1.0-HasInverse-Inverse";
+
+ public static void main(String[] args) {
+ try {
+ String s1 = URLEncoder.encode(TEST_STR, "UTF-8");
+ String s2 = URIStringUtils.escape(TEST_STR);
+ System.out.println("URLEncoder.encode(" + TEST_STR + "): " + s1);
+ System.out.println("URIStringUtils.escapeAll(" + TEST_STR + "): " + s2);
+ String ds1 = URLDecoder.decode(s1, "UTF-8");
+ String ds2 = URIStringUtils.unescape(s2);
+ System.out.println("ds1: " + ds1);
+ System.out.println("ds2: " + ds2);
+ String ds1x2 = URIStringUtils.unescape(s2);
+ String ds2x1 = URLDecoder.decode(s1, "UTF-8");
+ System.out.println("ds1x2: " + ds1x2);
+ System.out.println("ds2x1: " + ds2x1);
+
+ long start = System.nanoTime();
+ for (int i = 0; i < COUNT; ++i) {
+ String s = URLEncoder.encode(TEST_STR, "UTF-8");
+ }
+ long end = System.nanoTime();
+ System.out.println("URLEncoder: " + ((end-start)*1e-9));
+
+ long start2 = System.nanoTime();
+ for (int i = 0; i < COUNT; ++i) {
+ String s = URIStringUtils.escape(TEST_STR);
+ }
+ long end2 = System.nanoTime();
+ System.out.println("URIStringUtils.escape: " + ((end2-start2)*1e-9));
+
+ long start3 = System.nanoTime();
+ for (int i = 0; i < COUNT; ++i) {
+ String s = URLDecoder.decode(ds1, "UTF-8");
+ }
+ long end3 = System.nanoTime();
+ System.out.println("URLDecoder: " + ((end3-start3)*1e-9));
+
+ long start4 = System.nanoTime();
+ for (int i = 0; i < COUNT; ++i) {
+ String s = URIStringUtils.unescape(ds2);
+ }
+ long end4 = System.nanoTime();
+ System.out.println("URIStringUtils.decode: " + ((end4-start4)*1e-9));
+
+ } catch (UnsupportedEncodingException e1) {
+ e1.printStackTrace();
+ }
+ }
+
+}