You should try to optimise the Java code.
The best optimisation can be achieved by avoiding dynamic object creation inside loops.
An example:
# PHP
if w:
if w[0] == '<':
w += '>'
if(w.length()>0)
{
if(w.substring(0, 1).equals("<"))
{
w +=">";
}
}
Her
substring
will create a new string dynamically and perform a string comparison.
Why not just use
String.charAt()
and perform a character comparison?
if(w.length()>0)
{
if(w.charAt(0) == '<')
{
w += ">";
}
}
Another optimisation might be using class or static members to store the used regex search
Pattern
s. Then
Pattern.compile()
has not to be executed multiple times.