diff options
author | Endi Sukma Dewata <edewata@redhat.com> | 2012-01-04 21:43:21 -0600 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2012-01-10 20:23:18 -0600 |
commit | cd661cb7b0448cb95f1402dc3feb1457949e0383 (patch) | |
tree | 2be422350bf98e78b446602f7d1f0a30d3e6d31b /pki/base | |
parent | 58a343b58fb44c93579338b79eaf37089c753d19 (diff) | |
download | pki-cd661cb7b0448cb95f1402dc3feb1457949e0383.tar.gz pki-cd661cb7b0448cb95f1402dc3feb1457949e0383.tar.xz pki-cd661cb7b0448cb95f1402dc3feb1457949e0383.zip |
Added unit tests to measure conversion time.
New tests have been added to measure the conversion time.
Currently the results are not validated, they are used to compare
the performance before and after upgrading to Charset.
Ticket #3
Diffstat (limited to 'pki/base')
7 files changed, 366 insertions, 0 deletions
diff --git a/pki/base/util/test/com/netscape/security/util/BMPStringTest.java b/pki/base/util/test/com/netscape/security/util/BMPStringTest.java index e82ea50ce..93ce02016 100644 --- a/pki/base/util/test/com/netscape/security/util/BMPStringTest.java +++ b/pki/base/util/test/com/netscape/security/util/BMPStringTest.java @@ -209,4 +209,62 @@ public class BMPStringTest { Assert.assertEquals(input, output); } + + @Test + public void testEncodingTime() throws Exception { + + System.out.println("Encoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS + + StringTestUtil.MULTIBYTE_CHARS; + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.encode(tag, string); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.encode(tag, string); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } + + @Test + public void testDecodingTime() throws Exception { + + System.out.println("Decoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS + + StringTestUtil.MULTIBYTE_CHARS; + + byte[] data = JSSUtil.encode(tag, string); + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.decode(tag, data); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.decode(tag, data); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } } diff --git a/pki/base/util/test/com/netscape/security/util/IA5StringTest.java b/pki/base/util/test/com/netscape/security/util/IA5StringTest.java index a89624595..fca7f0103 100644 --- a/pki/base/util/test/com/netscape/security/util/IA5StringTest.java +++ b/pki/base/util/test/com/netscape/security/util/IA5StringTest.java @@ -210,4 +210,60 @@ public class IA5StringTest { Assert.assertTrue(e instanceof IOException); } } + + @Test + public void testEncodingTime() throws Exception { + + System.out.println("Encoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS; + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.encode(tag, string); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.encode(tag, string); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } + + @Test + public void testDecodingTime() throws Exception { + + System.out.println("Decoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS; + + byte[] data = JSSUtil.encode(tag, string); + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.decode(tag, data); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.decode(tag, data); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } } diff --git a/pki/base/util/test/com/netscape/security/util/JSSUtil.java b/pki/base/util/test/com/netscape/security/util/JSSUtil.java index abaab4272..fc899d560 100644 --- a/pki/base/util/test/com/netscape/security/util/JSSUtil.java +++ b/pki/base/util/test/com/netscape/security/util/JSSUtil.java @@ -2,11 +2,13 @@ package com.netscape.security.util; import netscape.security.util.DerValue; +import org.mozilla.jss.asn1.ASN1Template; import org.mozilla.jss.asn1.ASN1Util; import org.mozilla.jss.asn1.ASN1Value; import org.mozilla.jss.asn1.BMPString; import org.mozilla.jss.asn1.IA5String; import org.mozilla.jss.asn1.PrintableString; +import org.mozilla.jss.asn1.Tag; import org.mozilla.jss.asn1.TeletexString; import org.mozilla.jss.asn1.UTF8String; import org.mozilla.jss.asn1.UniversalString; @@ -40,4 +42,32 @@ public class JSSUtil { } return ASN1Util.encode(value); } + + public static String decode(byte tag, byte[] bytes) throws Exception { + ASN1Template template; + + switch (tag) { + case DerValue.tag_BMPString: + template = new BMPString.Template(); + break; + case DerValue.tag_IA5String: + template = new IA5String.Template(); + break; + case DerValue.tag_PrintableString: + template = new PrintableString.Template(); + break; + case DerValue.tag_T61String: + template = new TeletexString.Template(); + break; + case DerValue.tag_UniversalString: + template = new UniversalString.Template(); + break; + case DerValue.tag_UTF8String: + template = new UTF8String.Template(); + break; + default: + throw new Exception("Unsupported tag: "+tag); + } + return ASN1Util.decode(new Tag(Tag.UNIVERSAL, tag), template, bytes).toString(); + } } diff --git a/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java b/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java index 07525648b..6f0ba1d2a 100644 --- a/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java +++ b/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java @@ -233,4 +233,54 @@ public class PrintableStringTest { Assert.assertTrue(e instanceof IOException); } } + + @Test + public void testEncodingTime() throws Exception { + + System.out.println("Encoding time:"); + + String string = StringTestUtil.PRINTABLE_CHARS; + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.encode(tag, string); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.encode(tag, string); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } + + @Test + public void testDecodingTime() throws Exception { + + System.out.println("Decoding time:"); + + String string = StringTestUtil.PRINTABLE_CHARS; + + byte[] data = JSSUtil.encode(tag, string); + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.decode(tag, data); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.decode(tag, data); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } } diff --git a/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java b/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java index 92c61b9f9..fc205455f 100644 --- a/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java +++ b/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java @@ -210,4 +210,60 @@ public class TeletexStringTest { Assert.assertTrue(e instanceof IOException); } } + + @Test + public void testEncodingTime() throws Exception { + + System.out.println("Encoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS; + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.encode(tag, string); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.encode(tag, string); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } + + @Test + public void testDecodingTime() throws Exception { + + System.out.println("Decoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS; + + byte[] data = JSSUtil.encode(tag, string); + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.decode(tag, data); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.decode(tag, data); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } } diff --git a/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java b/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java index 48c20c49d..7f98c17c5 100644 --- a/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java +++ b/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java @@ -197,4 +197,62 @@ public class UTF8StringTest { Assert.assertEquals(input, output); } + + @Test + public void testEncodingTime() throws Exception { + + System.out.println("Encoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS + + StringTestUtil.MULTIBYTE_CHARS; + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.encode(tag, string); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.encode(tag, string); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } + + @Test + public void testDecodingTime() throws Exception { + + System.out.println("Decoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS + + StringTestUtil.MULTIBYTE_CHARS; + + byte[] data = JSSUtil.encode(tag, string); + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.decode(tag, data); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.decode(tag, data); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } } diff --git a/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java b/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java index 1e2c7efe0..53d45920d 100644 --- a/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java +++ b/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java @@ -197,4 +197,62 @@ public class UniversalStringTest { Assert.assertEquals(input, output); } + + @Test + public void testEncodingTime() throws Exception { + + System.out.println("Encoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS + + StringTestUtil.MULTIBYTE_CHARS; + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.encode(tag, string); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.encode(tag, string); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } + + @Test + public void testDecodingTime() throws Exception { + + System.out.println("Decoding time:"); + + String string = StringTestUtil.NULL_CHARS + + StringTestUtil.PRINTABLE_CHARS + + StringTestUtil.NON_PRINTABLE_CHARS + + StringTestUtil.CONTROL_CHARS + + StringTestUtil.MULTIBYTE_CHARS; + + byte[] data = JSSUtil.encode(tag, string); + + long t0 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) JSSUtil.decode(tag, data); + + long t1 = System.currentTimeMillis(); + + for (int i=0; i<10000; i++) StringTestUtil.decode(tag, data); + + long t2 = System.currentTimeMillis(); + + long time1 = t1 - t0; + long time2 = t2 - t1; + + System.out.println(" - JSS : "+time1+" ms"); + System.out.println(" - Internal: " + time2 + " ms"); + } } |