ASF Bugzilla – Attachment 29370 Details for
Bug 53867
Performance tuning solution for PageContextImpl.XmlEscape
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Comparison test case
EscapeTest.java (text/plain), 1.94 KB, created by
Sheldon Shao
on 2012-09-13 13:41:37 UTC
(
hide
)
Description:
Comparison test case
Filename:
MIME Type:
Creator:
Sheldon Shao
Created:
2012-09-13 13:41:37 UTC
Size:
1.94 KB
patch
obsolete
>package org.apache.jasper.runtime; > >import org.junit.Assert; >import org.junit.Test; > >public class EscapeTest { > > private static String oldXmlEscape(String s) { > if (s == null) > return null; > StringBuilder sb = new StringBuilder(); > for (int i = 0; i < s.length(); i++) { > char c = s.charAt(i); > if (c == '<') { > sb.append("<"); > } else if (c == '>') { > sb.append(">"); > } else if (c == '\'') { > sb.append("'"); // ' > } else if (c == '&') { > sb.append("&"); > } else if (c == '"') { > sb.append("""); // " > } else { > sb.append(c); > } > } > return sb.toString(); > } > > private static String[] array = new String[] { "Hello World!", > "<meta http-equiv=\"Content-Language\">", > "This connection has limited network connectivity. ", > "Please use this web page & to access file server resources. " }; > > @Test > public void testComparison() { > for (int i = 0; i < 10; i++) { > doComparison(); > } > } > > private static void doComparison() { > int count = 1000000; > > for (int j = 0; j < array.length; j++) { > Assert.assertEquals(oldXmlEscape(array[j]), > PageContextImpl.XmlEscape(array[j])); > } > > for (int i = 0; i < 100; i++) { > for (int j = 0; j < array.length; j++) { > oldXmlEscape(array[j]); > } > } > for (int i = 0; i < 100; i++) { > for (int j = 0; j < array.length; j++) { > PageContextImpl.XmlEscape(array[j]); > } > } > > long start = System.currentTimeMillis(); > for (int i = 0; i < count; i++) { > for (int j = 0; j < array.length; j++) { > oldXmlEscape(array[j]); > } > } > System.out > .println("Old escape:" + (System.currentTimeMillis() - start)); > start = System.currentTimeMillis(); > for (int i = 0; i < count; i++) { > for (int j = 0; j < array.length; j++) { > PageContextImpl.XmlEscape(array[j]); > } > } > System.out > .println("New escape:" + (System.currentTimeMillis() - start)); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 53867
:
29369
| 29370 |
29376