Add new performance test for large objects (many fields).

This commit is contained in:
Joel Leitch 2010-05-19 21:29:58 +00:00
parent 9c7bfc677a
commit 389f918bb8

View File

@ -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<String, Long> largeObject = new HashMap<String, Long>();
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<Map<String, Long>>() {}.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");