Menu

#6 Underscores around text gives performance problems

open
nobody
None
5
2008-09-01
2008-09-01
Anonymous
No

I have discovered what appears to be a bug that can lead to rather severe performance problems. The bug becomes evident when trying to "markdown" strings similar to "_ _ _ _ _ _ text _ _ _ _ _". The easiest test case that demonstrates this bug is the following code snippet: processor.markdown("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_");

After some testing, it seems like every additional "_ " BEFORE the "T" will increase the time for "markdown" to execute doubles. When having 26 "_ " (that is, underscore followed by space), the "markdown" takes about 100 seconds on my laptop. 25 "_ " takes around 50 seconds, and so on.

Below is the code snippet that can be used to reproduce the results.

If more details are needed, I can be contacted at Per Hallström <per.hallstrom@unikum.net>.

=== CODE ===
public void test2() {
String problematicPlaintext = "_T_";

for(int i=0;i<30;i++) {
long start = System.currentTimeMillis();
processor.markdown(problematicPlaintext);
long end = System.currentTimeMillis();
System.out.printf("i = %02d: %08d ms -- %56s\n", i, (end-start), problematicPlaintext);
problematicPlaintext = "_ " + problematicPlaintext;
}
}

=== EXAMPLE OUTPUT ===

i = 15: 00000051 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 16: 00000096 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 17: 00000207 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 18: 00000405 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 19: 00000905 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 20: 00001514 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 21: 00003008 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 22: 00006115 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 23: 00012232 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 24: 00024220 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_
i = 25: 00048662 ms -- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _T_

Discussion


Log in to post a comment.