#304 improved Normalization performance

This commit is contained in:
Timo Westkämper 2012-12-02 12:33:05 +02:00
parent 8c0fc959e2
commit 02ef2c352d
2 changed files with 25 additions and 2 deletions

View File

@ -25,7 +25,11 @@ public final class Normalization {
private static final Pattern MULTIPLICATION = Pattern.compile(START + NUMBER + WS + "\\*" + WS + NUMBER);
public static final String normalize(String queryString) {
public static final String normalize(String queryString) {
if (!hasOperators(queryString)) {
return queryString;
}
StringBuilder rv = null;
Matcher m = OPERATION.matcher(queryString);
int end = 0;
@ -74,8 +78,17 @@ public final class Normalization {
}
} else {
return queryString;
}
}
private static final boolean hasOperators(String queryString) {
for (int i = 0; i < queryString.length(); i++) {
char ch = queryString.charAt(i);
if (ch == '+' || ch == '-' || ch == '*' || ch == '/') {
return true;
}
}
return false;
}
private Normalization(){}

View File

@ -5,6 +5,16 @@ import static org.junit.Assert.*;
import org.junit.Test;
public class NormalizationTest {
@Test
public void Performance() {
int iterations = 1000000;
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
Normalization.normalize("select name from companies where id = ?");
}
System.err.println(System.currentTimeMillis() - start);
}
@Test
public void Variables() {