Skip to content

Commit 40dc57e

Browse files
committed
-added a performance test to execute test to compare with double type. the time consuming diff is very small after the change using BigDecimal
1 parent ef1c6da commit 40dc57e

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.networknt.schema;
2+
3+
import org.junit.Test;
4+
5+
import java.lang.annotation.Annotation;
6+
import java.lang.reflect.InvocationTargetException;
7+
import java.lang.reflect.Method;
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
import java.util.stream.Collectors;
12+
13+
public class MaximumValidatorPerfTest {
14+
MaximumValidatorTest test = new MaximumValidatorTest();
15+
16+
@Test
17+
public void testTime() throws InvocationTargetException, IllegalAccessException {
18+
test.setUp();
19+
String[] testMethodsToBeExecuted = {"testMaximumDoubleValue"};
20+
List<Method> testMethods = getTestMethods(testMethodsToBeExecuted);
21+
long start = System.currentTimeMillis();
22+
executeTests(testMethods, 200000);
23+
long end = System.currentTimeMillis();
24+
System.out.println("time to execute all tests using:" + (end - start) +"ms");
25+
}
26+
27+
public void executeTests(List<Method> methods, int executeTimes) throws InvocationTargetException, IllegalAccessException {
28+
29+
for(int i = 0; i < executeTimes; i++) {
30+
for(Method testMethod : methods) {
31+
testMethod.invoke(test);
32+
}
33+
}
34+
35+
}
36+
37+
public List<Method> getTestMethods(String[] methodNames) {
38+
Method[] methods = test.getClass().getMethods();
39+
List<Method> testMethods = new ArrayList<Method>();
40+
if(methodNames.length > 0) {
41+
for(String name : methodNames) {
42+
testMethods.addAll(Arrays.stream(methods).filter(m -> m.getName().equals(name)).collect(Collectors.toList()));
43+
}
44+
return testMethods;
45+
}
46+
for (Method m : methods) {
47+
Annotation[] annotations = m.getDeclaredAnnotations();
48+
boolean isTestMethod = false;
49+
for(Annotation annotation : annotations) {
50+
if(annotation.annotationType() == Test.class) {
51+
isTestMethod = true;
52+
}
53+
}
54+
if(isTestMethod) {
55+
//filter out incompatible test cases.
56+
if(!m.getName().equals("doubleValueCoarsing") && !m.getName().equals("negativeDoubleOverflowTest"))
57+
testMethods.add(m);
58+
}
59+
}
60+
return testMethods;
61+
}
62+
}

0 commit comments

Comments
 (0)