views

ok look a bit deeper into the concatting of strings.

what you should do is not use + but call concat..
That will speedup the current setup…
But i also optimized the code beneath the concat method so that in the next RC release it will be even much faster..

var maxReturnedRows = arguments[0]
var query = arguments[1]

var headerBgColor = '#cccccc'
var rowBgcolorLight = '#faf9f9'
var rowBgcolorDark = '#edeaea'

var dataset = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), query, null, maxReturnedRows);

var HTML = '<html>'.concat(
'<HEAD>',
'<style type="text/css">',
'   .header{',
'      font-family: Verdana, Verdana, Arial, Helvetica, sans-serif;',
'      font-size: 9px;',
'      background-color: #999999;',
'      border: 12px solid #000000;',
'      color: #ffffff; text-decoration: none;}',
'   .body{',
'      font-family: Verdana, Verdana, Arial, Helvetica, sans-serif;',
'      font-size: 9px;',
'      color: #000000; text-decoration: none;}',
'   </style>',
'</HEAD>',
'<TABLE border=1 class="body">');

//create headers
HTML = HTML.concat('<TR class="header"  >');
   for(var i=1 ; i <= dataset.getMaxColumnIndex() ; i++)
   {
       HTML = HTML.concat('<TD border=0>', dataset.getColumnName(i) , '</TD>');
   }
HTML = HTML.concat('</TR>');

//create rows and columns
for( var i = 1 ; i <= dataset.getMaxRowIndex() ; i++ )
{
   dataset.rowIndex = i;
   
   //set rowBgColor
   if(i%2==0)
   {
      HTML = HTML.concat('<TR bgcolor=',rowBgcolorLight,'>');
   }
   else
   {
      HTML = HTML.concat('<TR bgcolor=',rowBgcolorDark,'>');
   }

      for(var j=1 ; j <=  dataset.getMaxColumnIndex() ; j++)
      {
         HTML = HTML.concat('<TD border=0>',dataset[j],'</TD>');
      }
   HTML = HTML.concat('</TR>');
}
HTML = HTML.concat('</TABLE>');
return HTML;

It will still slow down a bit when it gets larger and larger. But by far not that exponential.

Notice the , instead of the + !!

jcompagner:
ok look a bit deeper into the concatting of strings.

what you should do is not use + but call concat..
That will speedup the current setup…
But i also optimized the code beneath the concat method so that in the next RC release it will be even much faster..

Cool, thanks!!

Reading all this I tend to conclude that it is advisable to use the concat function rather than the ‘+’. Is that correct?

Not in my findings. I have a list of records, build a data array and parse that array into html. With some 20 records, using concat was 25% faster. With more records I found these times in ms:

250 records, “regular” procedure: 23604, concat 217162
72 records, “regular” procedure: 7560, concat 14540

I noticed that at the beginning the conact way is much faster but gets increasingly slower the further you go. The CPU goes up to the roof, what does not happen if I do +=. I have also tried to write HTML in chunks of 32K as suggested here and figured that it is the fastest way with 2.2rc2.

So, the way to go seems not to concat but to ‘split’ the processed html into 32k length bits.

Could be interesting to test this with other text parsing code as well (like creating a rtf text/file)…

try it again with the latest RC3!
Then concat should always be faster.

Just made my benchmark-test:

16 records, 32K 2413ms, Concat 1642ms
250 records, 32K 20539ms, Concat 86895ms

do you have that benchmark for me?
Because the solution i tested the concat was XX times faster then anything else.

ahh wait!
you do that 32K trick with the +?

Please combine it
So use concat instead of the +.. But DO use the 32k check! And also use there concat..

That helps to make it a lot faster. Strangely, the += version is still faster… (although not much)

could i see that solution? (with both version + and concat)

I do think that it also depends how much and how big the strings are that you put into one concat call..

html += “test”
or
html = html.concat(“test”)

then i think the + would be faster.
But the strange thing is that you are saying that with small record size the concat is faster..

But the strange thing is that you are saying that with small record size the concat is faster..

Since I nested the concat version into chunks of ca. 32 KB, this is not true anymore. Still interested to see that? (I have to send you the whole monster, which might be helpful for other issues, too…).

try this:

var HTML = new java.lang.StringBuffer();

var maxReturnedRows = arguments[0]
var query = arguments[1]

var headerBgColor = '#cccccc'
var rowBgcolorLight = '#faf9f9'
var rowBgcolorDark = '#edeaea'

var dataset = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), query, null, maxReturnedRows);

HTML.append('<html>').append('<HEAD>').append('<style type="text/css">').append('   .header{').append('      font-family: Verdana, Verdana, Arial, Helvetica, sans-serif;'
).append('      font-size: 9px;').append('      background-color: #999999;').append('      border: 12px solid #000000;').append('      color: #ffffff; text-decoration: none;}'
).append('   .body{').append('      font-family: Verdana, Verdana, Arial, Helvetica, sans-serif;').append('      font-size: 9px;').append('      color: #000000; text-decoration: none;}'
).append('   </style>').append('</HEAD>').append('<TABLE border=1 class="body">');

//create headers
HTML.append('<TR class="header"  >');
   for(var i=1 ; i <= dataset.getMaxColumnIndex() ; i++)
   {
       HTML.append('<TD border=0>').append(dataset.getColumnName(i)).append('</TD>');
   }
HTML.append('</TR>');

//create rows and columns
for( var i = 1 ; i <= dataset.getMaxRowIndex() ; i++ )
{
   dataset.rowIndex = i;
   
   //set rowBgColor
   if(i%2==0)
   {
      HTML.append('<TR bgcolor=').append(rowBgcolorLight).append('>');
   }
   else
   {
      HTML.append('<TR bgcolor=').append(rowBgcolorDark).append('>');
   }

      for(var j=1 ; j <=  dataset.getMaxColumnIndex() ; j++)
      {
         HTML.concat('<TD border=0>').append(dataset[j]).append('</TD>');
      }
   HTML.append('</TR>');
}
HTML.append('</TABLE>');
return HTML.toString();

in 2.2RC4 all special tricks/calls shouldn’t be needed anymore.

just doe + where ever you want how much you want.
Also storing it in Xk blocks in a different variable shouldn’t be done anymore just constantly append one value.

I am looking forward to know some results with the new javascript implementation. (and look if everything goes ok)