# views

**URL:** <https://forum.servoy.com/t/views/121>\
**Category:** Classic Servoy\
**Created:** [June 7, 2003, 9:09am UTC](https://forum.servoy.com/t/views/121 "2003-06-07T09:09:38Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [March 14, 2005, 12:04pm UTC](https://forum.servoy.com/t/views/121/21 "2005-03-14T12:04:51Z")

</div>

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..

```auto
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 + !!

---

<div class="post-metadata">

**Author:** ![jonttu](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jonttu](https://forum.servoy.com/u/jonttu)\
**Post date:** [March 14, 2005, 11:34pm UTC](https://forum.servoy.com/t/views/121/22 "2005-03-14T23:34:28Z")

</div>

> 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!!

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [March 15, 2005, 7:17am UTC](https://forum.servoy.com/t/views/121/23 "2005-03-15T07:17:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [March 15, 2005, 11:18am UTC](https://forum.servoy.com/t/views/121/24 "2005-03-15T11:18:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [March 15, 2005, 11:29am UTC](https://forum.servoy.com/t/views/121/25 "2005-03-15T11:29:17Z")

</div>

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)…

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [March 17, 2005, 2:39pm UTC](https://forum.servoy.com/t/views/121/26 "2005-03-17T14:39:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [March 17, 2005, 3:06pm UTC](https://forum.servoy.com/t/views/121/27 "2005-03-17T15:06:33Z")

</div>

Just made my benchmark-test:

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

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [March 17, 2005, 3:18pm UTC](https://forum.servoy.com/t/views/121/28 "2005-03-17T15:18:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [March 17, 2005, 3:20pm UTC](https://forum.servoy.com/t/views/121/29 "2005-03-17T15:20:45Z")

</div>

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..

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [March 17, 2005, 3:58pm UTC](https://forum.servoy.com/t/views/121/30 "2005-03-17T15:58:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [March 17, 2005, 4:04pm UTC](https://forum.servoy.com/t/views/121/31 "2005-03-17T16:04:55Z")

</div>

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..

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [March 17, 2005, 4:10pm UTC](https://forum.servoy.com/t/views/121/32 "2005-03-17T16:10:06Z")

</div>

> 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…).

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [March 17, 2005, 4:47pm UTC](https://forum.servoy.com/t/views/121/33 "2005-03-17T16:47:07Z")

</div>

try this:

```auto
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();

```

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 8, 2005, 12:38pm UTC](https://forum.servoy.com/t/views/121/34 "2005-04-08T12:38:48Z")

</div>

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)

[Previous page](https://forum.servoy.com/t/views/121.md?page=1)
