From eac1beacc97818cbbda3ec4e6d0bf6c392e59509 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Mon, 13 Jul 2009 22:27:55 +0000 Subject: [PATCH] Added performance tests for byte array serialization and deserialization. --- .../google/gson/metrics/PerformanceTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java b/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java index 5140aa54..0ea2ee51 100644 --- a/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java +++ b/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java @@ -46,6 +46,44 @@ public class PerformanceTest extends TestCase { // This is here to prevent Junit for complaining when we disable all tests. } + // Last I tested, Gson was able to serialize upto 8MB byte array + public void disable_testByteArraySerialization() { + int size = 8096; + while (true) { + byte[] ba = new byte[size]; + for (int i = 0; i < size; ++i) { + ba[i] = 0x32; + } + String json = gson.toJson(ba); + System.out.printf("Gson could serialize a byte array of size: %d\n", size); + size <<= 2; + } + } + + // Last I tested, Gson was able to deserialize a byte array of 32KB + public void disable_testByteArrayDeserialization() { + int numElements = 8096; + while (true) { + StringBuilder sb = new StringBuilder(numElements*2); + sb.append("["); + boolean first = true; + for (int i = 0; i < numElements; ++i) { + if (first) { + first = false; + } else { + sb.append(","); + } + sb.append("5"); + } + sb.append("]"); + String json = sb.toString(); + byte[] ba = gson.fromJson(json, byte[].class); + System.out.printf("Gson could handle a byte array of size: %d\n", ba.length); + numElements <<= 2; + } + } + + public void disabled_testStringDeserializationPerformance() { StringBuilder sb = new StringBuilder(8096); sb.append("Error Yippie");