diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java index 2c62bbe0c1..ec1e3c8aba 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java @@ -203,16 +203,15 @@ public class GenericConversionServiceTests { @Test public void testPerformance1() { GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); - StopWatch watch = new StopWatch("conversionPerformance"); + StopWatch watch = new StopWatch("integer->string conversionPerformance"); watch.start("convert 4,000,000 with conversion service"); for (int i = 0; i < 4000000; i++) { conversionService.convert(3, String.class); } watch.stop(); - watch.start("convert 4,000,000 with converter directly"); - ObjectToStringConverter converter = new ObjectToStringConverter(); + watch.start("convert 4,000,000 manually"); for (int i = 0; i < 4000000; i++) { - converter.convert(3, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class)); + new Integer(3).toString(); } watch.stop(); System.out.println(watch.prettyPrint()); @@ -221,8 +220,8 @@ public class GenericConversionServiceTests { @Test public void testPerformance2() throws Exception { GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); - StopWatch watch = new StopWatch("conversionPerformance"); - watch.start("convert 4,000,000"); + StopWatch watch = new StopWatch("list -> list conversionPerformance"); + watch.start("convert 4,000,000 with conversion service"); List source = new LinkedList(); source.add("1"); source.add("2"); @@ -232,6 +231,14 @@ public class GenericConversionServiceTests { conversionService.convert(source, TypeDescriptor.forObject(source), td); } watch.stop(); + watch.start("convert 4,000,000 manually"); + for (int i = 0; i < 4000000; i++) { + List target = new ArrayList(source.size()); + for (String element : source) { + target.add(Integer.valueOf(element)); + } + } + watch.stop(); System.out.println(watch.prettyPrint()); } @@ -240,8 +247,8 @@ public class GenericConversionServiceTests { @Test public void testPerformance3() throws Exception { GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); - StopWatch watch = new StopWatch("conversionPerformance"); - watch.start("convert 4,000,000"); + StopWatch watch = new StopWatch("map -> map conversionPerformance"); + watch.start("convert 4,000,000 with conversion service"); Map source = new HashMap(); source.put("1", "1"); source.put("2", "2"); @@ -251,6 +258,14 @@ public class GenericConversionServiceTests { conversionService.convert(source, TypeDescriptor.forObject(source), td); } watch.stop(); + watch.start("convert 4,000,000 manually"); + for (int i = 0; i < 4000000; i++) { + Map target = new HashMap(source.size()); + for (Map.Entry entry : source.entrySet()) { + target.put(entry.getKey(), Integer.valueOf(entry.getValue())); + } + } + watch.stop(); System.out.println(watch.prettyPrint()); }