From 86906d1b4de83fd48ee30d6606de918bbc4a13fd Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Mon, 19 Apr 2010 20:22:01 +0000 Subject: [PATCH] checking in performance tests --- .../springframework/core/convert/TypeDescriptor.java | 12 ++++-------- .../convert/support/GenericConversionService.java | 12 +++++++----- .../support/GenericConversionServiceTests.java | 12 +++++++----- .../src/test/resources/log4j.xml | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index f85abf39a3..84ab48f7a9 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -400,6 +400,9 @@ public class TypeDescriptor { return false; } TypeDescriptor td = (TypeDescriptor) obj; + if (this == td) { + return true; + } boolean annotatedTypeEquals = getType().equals(td.getType()) && ObjectUtils.nullSafeEquals(getAnnotations(), td.getAnnotations()); if (isCollection()) { return annotatedTypeEquals && ObjectUtils.nullSafeEquals(getElementType(), td.getElementType()); @@ -411,14 +414,7 @@ public class TypeDescriptor { } public int hashCode() { - int annotatedTypeHash = getType().hashCode() + ObjectUtils.nullSafeHashCode(getAnnotations()); - if (isCollection()) { - return annotatedTypeHash + ObjectUtils.nullSafeHashCode(getElementType()); - } else if (isMap()) { - return annotatedTypeHash + ObjectUtils.nullSafeHashCode(getMapKeyType()) + ObjectUtils.nullSafeHashCode(getMapValueType()); - } else { - return annotatedTypeHash; - } + return getType().hashCode(); } /** diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index 1df21ae687..8def693f59 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -64,6 +64,9 @@ public class GenericConversionService implements ConversionService, ConverterReg public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return source; } + public String toString() { + return "NO_OP"; + } }; private static final GenericConverter NO_MATCH = new GenericConverter() { @@ -396,7 +399,6 @@ public class GenericConversionService implements ConversionService, ConverterReg private GenericConverter getMatchingConverterForTarget(TypeDescriptor sourceType, TypeDescriptor targetType, Map, MatchableConverters> converters) { - Class targetObjectType = targetType.getObjectType(); if (targetObjectType.isInterface()) { LinkedList> classQueue = new LinkedList>(); @@ -594,11 +596,11 @@ public class GenericConversionService implements ConversionService, ConverterReg } } - private static class ConverterCacheKey { + private static final class ConverterCacheKey { - private TypeDescriptor sourceType; + private final TypeDescriptor sourceType; - private TypeDescriptor targetType; + private final TypeDescriptor targetType; public ConverterCacheKey(TypeDescriptor sourceType, TypeDescriptor targetType) { this.sourceType = sourceType; @@ -614,7 +616,7 @@ public class GenericConversionService implements ConversionService, ConverterReg } public int hashCode() { - return sourceType.hashCode() + targetType.hashCode(); + return sourceType.hashCode() * 29 + targetType.hashCode(); } public String toString() { 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 5ee47eec7f..2c62bbe0c1 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 @@ -30,7 +30,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.junit.Ignore; import org.junit.Test; import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConverterNotFoundException; @@ -202,20 +201,24 @@ public class GenericConversionServiceTests { } @Test - @Ignore public void testPerformance1() { GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); StopWatch watch = new StopWatch("conversionPerformance"); - watch.start("convert 4,000,000"); + 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(); + for (int i = 0; i < 4000000; i++) { + converter.convert(3, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class)); + } + watch.stop(); System.out.println(watch.prettyPrint()); } @Test - @Ignore public void testPerformance2() throws Exception { GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); StopWatch watch = new StopWatch("conversionPerformance"); @@ -235,7 +238,6 @@ public class GenericConversionServiceTests { public static List list; @Test - @Ignore public void testPerformance3() throws Exception { GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService(); StopWatch watch = new StopWatch("conversionPerformance"); diff --git a/org.springframework.core/src/test/resources/log4j.xml b/org.springframework.core/src/test/resources/log4j.xml index c68603bf90..576b4395d7 100644 --- a/org.springframework.core/src/test/resources/log4j.xml +++ b/org.springframework.core/src/test/resources/log4j.xml @@ -12,7 +12,7 @@ - +