checking in performance tests
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Class<?>, MatchableConverters> converters) {
|
||||
|
||||
Class<?> targetObjectType = targetType.getObjectType();
|
||||
if (targetObjectType.isInterface()) {
|
||||
LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>();
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<Integer> list;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testPerformance3() throws Exception {
|
||||
GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
|
||||
StopWatch watch = new StopWatch("conversionPerformance");
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework.core">
|
||||
<level value="trace" />
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
|
||||
Reference in New Issue
Block a user