From 389f918bb83c34f6590351cf7b4a748ae358c890 Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Wed, 19 May 2010 21:29:58 +0000 Subject: [PATCH] Add new performance test for large objects (many fields). --- .../google/gson/metrics/PerformanceTest.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) 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 a9460ea6..684c3e34 100644 --- a/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java +++ b/gson/src/test/java/com/google/gson/metrics/PerformanceTest.java @@ -16,18 +16,20 @@ package com.google.gson.metrics; +import java.io.StringWriter; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + import com.google.gson.Gson; import com.google.gson.JsonParseException; import com.google.gson.annotations.Expose; import com.google.gson.reflect.TypeToken; -import junit.framework.TestCase; - -import java.io.StringWriter; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - /** * Tests to measure performance for Gson. All tests in this file will be disabled in code. To run * them remove disabled_ prefix from the tests and run them. @@ -215,6 +217,24 @@ public class PerformanceTest extends TestCase { long avg = (t2 - t1) / NUM_ITERATIONS; System.out.printf("Deserialize classes avg time: %d ms\n", avg); } + + public void disable_testLargeObjectSerializationAndDeserialization() { + Map largeObject = new HashMap(); + for (long l = 0; l < 100000; l++) { + largeObject.put("field" + l, l); + } + + long t1 = System.currentTimeMillis(); + String json = gson.toJson(largeObject); + long t2 = System.currentTimeMillis(); + System.out.printf("Large object serialized in: %d ms\n", (t2 - t1)); + + t1 = System.currentTimeMillis(); + gson.fromJson(json, new TypeToken>() {}.getType()); + t2 = System.currentTimeMillis(); + System.out.printf("Large object deserialized in: %d ms\n", (t2 - t1)); + + } public void disable_testSerializeExposedClasses() { ClassWithListOfObjects c1 = new ClassWithListOfObjects("str");