--- /dev/null
+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